--- id: css-input-focus-and-icons title: "CSS Input Focus and Icons" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["CSS form focus", "input focus styling", "focus pseudo-class", "search input icon", "animated search input"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "forms", "focus", "pseudo-class"] raw_sources: ["https://www.w3schools.com/css/css_form_focus.asp"] applied_in: [] github_commit: "" --- # [[CSS Input Focus and Icons]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The `:focus` pseudo-class lets you restyle an input the moment it is clicked into, and combined with `outline: none;`, `background-image`, and `transition`, you can build clean focus states, icon-bearing fields, and animated search boxes. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Default focus outline** β€” by default, some browsers add a blue outline around an input when it gets focus (is clicked on); `outline: none;` removes this behavior. [S1] - **`:focus` selector** β€” used to do something with an input field when it gets focus. [S1] - **Input icons** β€” an icon can be placed inside an input using `background-image` positioned via `background-position`, with a large left padding reserving space for the icon. [S1] - **Animated focus** β€” the `transition` property can animate input changes (e.g., width) when the field gains focus. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Reset-then-restyle on focus** β€” remove the native outline, then express focus visually through your own property (background color, border). [S1] - **Icon = background-image + padding** β€” render a decorative/functional icon by layering a non-repeating background image and reserving its space with `padding-left`. [S1] - **Focus-driven animation** β€” declare `transition` on the base selector and the target value on the `:focus` selector so the change eases in. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Style Input with Focus** By default, some browsers will add a blue outline around the input when it gets focus (clicked on). You can remove this behavior by adding `outline: none;` to the input. Use the `:focus` selector to do something with the input field when it gets focus. [S1] Change the background color to lightblue on focus: [S1] ```css input[type=text]:focus { background-color: lightblue; } ``` Add a border on focus: [S1] ```css input[type=text]:focus { border: 3px solid #555; } ``` **Style Input with Icon/Image** If you want an icon inside the input, use the `background-image` property and position it with the `background-position` property. Also notice that we add a large left padding to reserve the space of the icon: [S1] ```css input[type=text] { background-color: white; background-image: url('searchicon.png'); background-position: 10px 10px; background-repeat: no-repeat; padding-left: 40px; } ``` **Animated Search Input** In this example we use the CSS `transition` property to animate the width of the search input when it gets focus. You will learn more about the `transition` property later, in the CSS Transitions chapter. [S1] ```css input[type=text] { transition: width 0.4s ease-in-out; } input[type=text]:focus { width: 100%; } ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own examples are the applied cases: a lightblue focus background, a 3px focus border, a search field with an embedded `searchicon.png`, and a search box that animates to full width on focus. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Restyle on focus (language: CSS): ```css input[type=text]:focus { background-color: lightblue; } ``` Icon inside input (language: CSS): ```css input[type=text] { background-image: url('searchicon.png'); background-position: 10px 10px; background-repeat: no-repeat; padding-left: 40px; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Other Form Elements]], [[CSS Forms]], [[CSS Pseudo-classes]], [[CSS Transitions]] - **μ°Έμ‘° λ§₯락:** Referenced when styling interactive form fields and search inputs for visible focus feedback. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Input Focus and Icons β€” https://www.w3schools.com/css/css_form_focus.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Input Focus and Icons" page (Astra wiki-curation, P-Reinforce v3.1 format).