32 CSS Search Box & Search Bar Designs
Floating Label
Material-style floating label that snaps up when the input is focused or filled — uses :placeholder-shown for a JS-free implementation.
Floating Label the 5th of 32 designs in the 32 CSS Search Box & Search Bar Designs collection. The design is implemented in pure CSS — no JavaScript required. Copy the HTML and CSS panels below into your project. Because the demo is pure CSS, it works in any framework or templating engine you happen to use. The design honours prefers-reduced-motion and uses real semantic markup, so it ships accessibility-ready out of the box.
Live preview
The code
<form class="csb-float" role="search"> <input id="csb-float-i" type="search" name="q" placeholder=" " /> <label for="csb-float-i">Search anything</label> </form>
.csb-float {
position: relative; display: inline-block;
}
.csb-float input {
width: 240px; padding: 18px 14px 8px;
background: #1a1a28;
border: 1px solid rgba(255,255,255,0.08);
border-radius: 8px;
color: #f0eeff; font: 500 14px/1 system-ui, sans-serif;
outline: none;
transition: border-color 0.2s;
}
.csb-float input:focus { border-color: #7c6cff; }
.csb-float label {
position: absolute;
left: 14px; top: 50%;
transform: translateY(-50%);
color: #7a7899; font: 500 14px/1 system-ui, sans-serif;
pointer-events: none;
transition: top 0.2s, font-size 0.2s, color 0.2s;
}
.csb-float input:focus + label,
.csb-float input:not(:placeholder-shown) + label {
top: 12px;
font-size: 10.5px;
color: #a78bfa;
letter-spacing: 0.06em;
text-transform: uppercase;
}