CSS Floating Label Select
A native select with a label that sits inside like a placeholder, then floats up once an option is chosen.
<label class="float-select">
<select name="country" required>
<option value="" disabled selected></option>
<option>Canada</option>
<option>Germany</option>
<option>Japan</option>
</select>
<span>Country</span>
</label>
.float-select {
position: relative;
display: block;
width: 240px;
font-family: system-ui, sans-serif;
}
.float-select select {
box-sizing: border-box;
width: 100%;
height: 54px;
padding: 20px 40px 4px 14px;
border: 1.5px solid #a7f3d0;
border-radius: 10px;
background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23047857' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center / 16px;
color: #064e3b;
font: 16px system-ui, sans-serif;
-webkit-appearance: none;
appearance: none;
cursor: pointer;
}
.float-select span {
position: absolute;
top: 10px;
left: 15px;
color: #059669;
font-size: 12px;
pointer-events: none;
transition: top 0.2s ease, font-size 0.2s ease;
}
.float-select select:invalid + span {
top: 17px;
color: #6b7280;
font-size: 16px;
}
.float-select select:focus-visible {
border-color: #059669;
outline: none;
box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.15);
}
@media (prefers-reduced-motion: reduce) {
.float-select span {
transition: none;
}
}
About this CSS Floating Label Select
This CSS Floating Label Select is 49 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses transitions, box shadows, keyboard focus styles and reduced-motion support. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#a7f3d0#fff#064e3b#059669#6b7280
How to use this floating label select
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.float-selectclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.