CSS Outlined Floating Label

A Material-style outlined input whose label shrinks into a notch on the top border when focused or filled.

  • floating label
  • outlined
  • material
  • notch
  • input
  • placeholder-shown
HTML
<label class="outlined">
  <input type="text" name="name" autocomplete="name" placeholder=" ">
  <span>Full name</span>
</label>
CSS
.outlined {
  --accent: #0d9488;
  position: relative;
  display: block;
  width: 240px;
  font-family: system-ui, sans-serif;
}

.outlined input {
  box-sizing: border-box;
  width: 100%;
  padding: 14px 14px;
  border: 1.5px solid #a1a1aa;
  border-radius: 8px;
  background: #fff;
  color: #18181b;
  font: 16px system-ui, sans-serif;
  outline: none;
  transition: border-color 0.2s ease;
}

.outlined span {
  position: absolute;
  top: 50%;
  left: 10px;
  padding: 0 4px;
  background: #fff;
  color: #71717a;
  font-size: 16px;
  line-height: 1;
  pointer-events: none;
  transform: translateY(-50%);
  transition: top 0.2s ease, font-size 0.2s ease, color 0.2s ease;
}

.outlined input:hover {
  border-color: #52525b;
}

.outlined input:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.outlined input:focus + span,
.outlined input:not(:placeholder-shown) + span {
  top: 0;
  font-size: 12px;
}

.outlined input:focus + span {
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .outlined span {
    transition: none;
  }
}

About this CSS Outlined Floating Label

This CSS Outlined Floating Label is 59 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and custom properties. 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

Change these custom properties to restyle the outlined floating label without touching the rest of the CSS:

PropertyDefault
--accent#0d9488

How to use this outlined floating label

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .outlined class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in 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.

Feedback