{"id":1821,"date":"2024-04-25T17:38:05","date_gmt":"2024-04-25T23:38:05","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=1821"},"modified":"2024-04-25T17:38:06","modified_gmt":"2024-04-25T23:38:06","slug":"the-html-css-and-svg-for-a-classic-search-form","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/the-html-css-and-svg-for-a-classic-search-form\/","title":{"rendered":"The HTML, CSS, and SVG for a Classic Search Form"},"content":{"rendered":"\n<p>Let&#8217;s build a search form that looks like this:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"364\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.36%402x.png?resize=906%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-1826\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.36%402x.png?w=906&amp;ssl=1 906w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.36%402x.png?resize=300%2C121&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.36%402x.png?resize=768%2C309&amp;ssl=1 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"364\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.37%402x.png?resize=906%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-1829\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.37%402x.png?w=906&amp;ssl=1 906w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.37%402x.png?resize=300%2C121&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.37%402x.png?resize=768%2C309&amp;ssl=1 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"364\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.31%402x.png?resize=906%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-1831\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.31%402x.png?w=906&amp;ssl=1 906w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.31%402x.png?resize=300%2C121&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.31%402x.png?resize=768%2C309&amp;ssl=1 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"364\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.47%402x.png?resize=906%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-1827\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.47%402x.png?w=906&amp;ssl=1 906w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.47%402x.png?resize=300%2C121&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.24.47%402x.png?resize=768%2C309&amp;ssl=1 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"364\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.06%402x.png?resize=906%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-1828\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.06%402x.png?w=906&amp;ssl=1 906w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.06%402x.png?resize=300%2C121&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.06%402x.png?resize=768%2C309&amp;ssl=1 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"364\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.24%402x.png?resize=906%2C364&#038;ssl=1\" alt=\"\" class=\"wp-image-1830\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.24%402x.png?w=906&amp;ssl=1 906w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.24%402x.png?resize=300%2C121&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/CleanShot-2024-04-24-at-10.25.24%402x.png?resize=768%2C309&amp;ssl=1 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p>That feels like the absolute bowl-it-down-the-middle search form right now. Looks good but nothing fancy. And yet, coding it in HTML and CSS I don&#8217;t think is perfectly intuitive and makes use of a handful of decently modern and slightly lesser used features.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Label-Wrapping HTML<\/h2>\n\n\n\n<p>At a glance, this looks like an <code>&lt;input&gt;<\/code> all by itself. Perhaps the placeholder text is pushed in with some <code>text-indent<\/code> or something and an <code>&lt;svg&gt;<\/code> icon is plopped on top. But no, that&#8217;s actually harder than what we&#8217;ve done here. Instead we&#8217;re going to wrap the input in a label like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">label<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"searchLabelWrap\"<\/span>&gt;<\/span>\n  Search\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"search\"<\/span> <span class=\"hljs-attr\">placeholder<\/span>=<span class=\"hljs-string\">\"Search\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"searchInput\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"s\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">label<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This wrapping means the label and input are automatically tied to each other (e.g. clicking the label will focus the input) without having to use the <code>for<\/code> attribute and a matching <code>id<\/code>. <\/p>\n\n\n\n<p>We&#8217;re also using the <code>search<\/code> type here on the input, which is semantically correct, but also gives us the free UX of having a \u2716\ufe0f &#8220;clear search&#8221; icon in the input for free.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping All That in a Search and Form element<\/h2>\n\n\n\n<p>HTML now has a <code>&lt;search&gt;<\/code> element, so again that&#8217;s a semantically smart choice, and we&#8217;ll also use a <code>&lt;form&gt;<\/code> element so that submitting the search can be done with the Enter key. Gotta think UX! If you don&#8217;t like the extra wrapper, you could put <code>role=\"search\"<\/code> on the <code>&lt;form&gt;<\/code>, but I like it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table\"><mark class='shcb-loc'><span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">search<\/span>&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">form<\/span> <span class=\"hljs-attr\">action<\/span>=<span class=\"hljs-string\">\"\/search\"<\/span> <span class=\"hljs-attr\">method<\/span>=<span class=\"hljs-string\">\"GET\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"searchForm\"<\/span>&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">label<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"searchLabelWrap\"<\/span>&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span>       ...\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">label<\/span>&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">form<\/span>&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">search<\/span>&gt;<\/span> \n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The GET <code>method<\/code> means it will append our search term as a search parameter which is usually a desirable trait of a search form. The <code>name<\/code> attribute of the input will be the search param key. That&#8217;s looking pretty solid right there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hiding the Label, Adding an Icon<\/h2>\n\n\n\n<p>We definitely need there to be a text label for the input for screen readers, but since we&#8217;ll be visually marking the input with both a visual icon and placeholder text, I think it&#8217;s OK to hide the text label while leaving it accessible. <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table\"><span class='shcb-loc'><span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">label<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"searchLabelWrap\"<\/span>&gt;<\/span>\n<\/span><\/span><mark class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"visually-hidden\"<\/span>&gt;<\/span>Search<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span>\n<\/span><\/mark><mark class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">svg<\/span> <span class=\"hljs-attr\">viewBox<\/span>=<span class=\"hljs-string\">\"0 0 512 512\"<\/span> <span class=\"hljs-attr\">aria-hidden<\/span>=<span class=\"hljs-string\">\"true\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"icon\"<\/span>&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span>    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">path<\/span> <span class=\"hljs-attr\">d<\/span>=<span class=\"hljs-string\">\"...\"<\/span> \/&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">svg<\/span>&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"search\"<\/span> <span class=\"hljs-attr\">placeholder<\/span>=<span class=\"hljs-string\">\"Search\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"searchInput\"<\/span>&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">label<\/span>&gt;<\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.visually-hidden<\/span> {\n  <span class=\"hljs-attribute\">position<\/span>: absolute;\n  <span class=\"hljs-attribute\">left<\/span>: -<span class=\"hljs-number\">9999px<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Label Wrapping Styling<\/h2>\n\n\n\n<p>Without any CSS, we&#8217;re in this sort of situation:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"390\" height=\"104\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-2024-04-25-at-3.25.24%E2%80%AFPM.png?resize=390%2C104&#038;ssl=1\" alt=\"\" class=\"wp-image-1872\" style=\"width:255px;height:auto\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-2024-04-25-at-3.25.24%E2%80%AFPM.png?w=390&amp;ssl=1 390w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-2024-04-25-at-3.25.24%E2%80%AFPM.png?resize=300%2C80&amp;ssl=1 300w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/figure>\n<\/div>\n\n\n<p>Perfectly functional, but we&#8217;ve got work to do. Visually, we want the icon to appear <em>inside<\/em> the &#8220;input&#8221; area. So we&#8217;ll actually apply the background to the <code>searchLabelWrap<\/code> instead here, and wipe out all the styling on the input itself. While we&#8217;re at it, let&#8217;s think about Dark Mode\/Light Mode and use the newfangled <code>light-dark()<\/code> function. This is very new so, ya know, do what you gotta do. We&#8217;ll keep things aligned with flexbox and apply very chill other styles:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.searchLabelWrap<\/span> {\n  <span class=\"hljs-attribute\">display<\/span>: flex;\n  <span class=\"hljs-attribute\">gap<\/span>: <span class=\"hljs-number\">0.5rem<\/span>;\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-built_in\">light-dark<\/span>(var(--gray-light), <span class=\"hljs-built_in\">var<\/span>(--gray-dark));\n  <span class=\"hljs-attribute\">padding<\/span>: <span class=\"hljs-number\">0.5rem<\/span> <span class=\"hljs-number\">1rem<\/span>;\n  <span class=\"hljs-attribute\">border-radius<\/span>: <span class=\"hljs-number\">0.5rem<\/span>;\n}\n\n<span class=\"hljs-selector-class\">.searchInput<\/span> {\n  <span class=\"hljs-attribute\">border<\/span>: <span class=\"hljs-number\">0<\/span>;\n  <span class=\"hljs-attribute\">outline<\/span>: <span class=\"hljs-number\">0<\/span>; <span class=\"hljs-comment\">\/* focus style on parent *\/<\/span>\n  <span class=\"hljs-attribute\">background<\/span>: transparent;\n  <span class=\"hljs-attribute\">font<\/span>: inherit;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>We&#8217;re doing the sin of removing the focus style on the input, which isn&#8217;t a very accessible thing to do. So we gotta bring that back!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Focus Within FTW<\/h2>\n\n\n\n<p>It&#8217;s actually the input itself which receives the <code>:focus<\/code>, but we can target the parent here instead. Maybe use <code>:has()<\/code> you say? Like <code>:has(input:focus)<\/code> could work, but there is actually a cleaner way here:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.searchLabelWrap<\/span> {\n  ...\n\n  &amp;:focus-within {\n    <span class=\"hljs-attribute\">outline<\/span>: <span class=\"hljs-number\">2px<\/span> solid <span class=\"hljs-built_in\">var<\/span>(--focus-blue);\n    <span class=\"hljs-attribute\">outline-offset<\/span>: <span class=\"hljs-number\">2px<\/span>;\n  }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>I love <code>:focus-within<\/code> it&#8217;s so cool. It was kinda the OG has and it was theorized when it came out that it could be a gateway to <code>:has()<\/code> and that&#8217;s totally what happened. <\/p>\n\n\n\n<p>Also notice the <code>outline-offset<\/code> there. I think that&#8217;s a nice touch to push the somewhat <a href=\"https:\/\/daverupert.com\/2024\/01\/focus-visible-love\/\">beefy<\/a> outline away a smidge.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"646\" height=\"222\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-2024-04-25-at-3.47.24%E2%80%AFPM.png?resize=646%2C222&#038;ssl=1\" alt=\"\" class=\"wp-image-1873\" style=\"width:332px;height:auto\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-2024-04-25-at-3.47.24%E2%80%AFPM.png?w=646&amp;ssl=1 646w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-2024-04-25-at-3.47.24%E2%80%AFPM.png?resize=300%2C103&amp;ssl=1 300w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">The Icon<\/h2>\n\n\n\n<p>I&#8217;m a fan of just using inline SVG for icons. No network request and easy to style my friends. Here&#8217;s one:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">svg<\/span> <span class=\"hljs-attr\">viewBox<\/span>=<span class=\"hljs-string\">\"0 0 512 512\"<\/span> <span class=\"hljs-attr\">aria-hidden<\/span>=<span class=\"hljs-string\">\"true\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"icon\"<\/span> <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"\n20\"<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">path<\/span> <span class=\"hljs-attr\">d<\/span>=<span class=\"hljs-string\">\"M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z\"<\/span> \/&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">svg<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>I like tossing a <code>width<\/code> on there because an <code>&lt;svg&gt;<\/code> with a <code>viewBox<\/code> before CSS loads can load <em>super<\/em> wide on the screen and it&#8217;s akward. CSS will come in and make it right here:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.icon<\/span> {\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">1rem<\/span>;\n  <span class=\"hljs-attribute\">aspect-ratio<\/span>: <span class=\"hljs-number\">1<\/span>;\n  <span class=\"hljs-attribute\">fill<\/span>: currentColor;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You could apply different styling, but here I&#8217;m making the icon text follow the text color so it&#8217;s easier to update. The icon is also essentially in a square area hence the simple <code>aspect-ratio<\/code>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Colors<\/h2>\n\n\n\n<p>I used a few <code>--custom-properties<\/code> as we went. I&#8217;ll define them here at the root, as well as ensure our page knows we&#8217;re intending to support both modes:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">html<\/span> {\n  <span class=\"hljs-attribute\">color-scheme<\/span>: light dark;\n\n  <span class=\"hljs-attribute\">--gray-light<\/span>: <span class=\"hljs-number\">#eee<\/span>;\n  <span class=\"hljs-attribute\">--gray-dark<\/span>: <span class=\"hljs-number\">#333<\/span>;\n  <span class=\"hljs-attribute\">--focus-blue<\/span>: <span class=\"hljs-number\">#1976d2<\/span>;\n}\n\n<span class=\"hljs-selector-tag\">body<\/span> {\n  <span class=\"hljs-attribute\">background<\/span>: <span class=\"hljs-built_in\">light-dark<\/span>(white, black);\n  <span class=\"hljs-attribute\">color<\/span>: <span class=\"hljs-built_in\">light-dark<\/span>(black, white);\n  <span class=\"hljs-attribute\">font<\/span>: <span class=\"hljs-number\">100%<\/span>\/<span class=\"hljs-number\">1.5<\/span> system-ui, sans-serif;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>That&#8217;ll do use nicely, finishing things off. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demo<\/h2>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_PogyzvQ\" src=\"\/\/codepen.io\/anon\/embed\/PogyzvQ?height=450&amp;theme-id=47434&amp;slug-hash=PogyzvQ&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed PogyzvQ\" title=\"CodePen Embed PogyzvQ\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s build a search form that looks like this: That feels like the absolute bowl-it-down-the-middle search form right now. Looks good but nothing fancy. And yet, coding it in HTML and CSS I don&#8217;t think is perfectly intuitive and makes use of a handful of decently modern and slightly lesser used features. The Label-Wrapping HTML [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1875,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[7,31,166],"class_list":["post-1821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-css","tag-html","tag-search"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/search-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=1821"}],"version-history":[{"count":7,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1821\/revisions"}],"predecessor-version":[{"id":1879,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1821\/revisions\/1879"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/1875"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=1821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=1821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=1821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}