Contact Form with Floating Labels

This contact form uses floating labels to keep the layout clean while maintaining clear field context. Ideal for modern business websites.

HTML

<form class="contact-float">
  <h3>Contact Us</h3>
  <p class="subtitle">We’ll get back to you shortly</p>

  <div class="field">
    <input type="text" placeholder=" " required>
    <label>Name</label>
  </div>

  <div class="field">
    <input type="email" placeholder=" " required>
    <label>Email</label>
  </div>

  <div class="field">
    <textarea placeholder=" " rows="4" required></textarea>
    <label>Message</label>
  </div>

  <button type="button">Send Message</button>
</form>

Important: Floating labels require placeholder=" " (space).

CSS

:root{
  --bg:#f8fafc;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --border:#e5e7eb;

  --primary:#2563eb;
  --primary-dark:#1d4ed8;
}

@media (prefers-color-scheme: dark){
  :root{
    --bg:#020617;
    --card:#020617;
    --text:#e5e7eb;
    --muted:#94a3b8;
    --border:#1f2937;

    --primary:#3b82f6;
    --primary-dark:#60a5fa;
  }
}


.contact-float{
  max-width:420px;
  margin:80px auto;
  padding:32px;

  background:var(--card);
  border-radius:18px;
  border:1px solid var(--border);
  box-shadow:0 16px 40px rgba(0,0,0,.12);

  color:var(--text);
  font-family:system-ui, -apple-system, sans-serif;
}

.contact-float h3{
  font-size:22px;
  margin-bottom:6px;
}

.contact-float .subtitle{
  font-size:14px;
  color:var(--muted);
  margin-bottom:24px;
}


.field{
  position:relative;
  margin-bottom:20px;
}

.field input,
.field textarea{
  width:100%;
  padding:14px 16px;
  font-size:15px;

  border-radius:12px;
  border:1px solid var(--border);
  background:linear-gradient(180deg,var(--card),var(--bg));
  color:var(--text);

  outline:none;
  resize:none;
  transition:border .2s ease, box-shadow .2s ease;
}

.field input:focus,
.field textarea:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 4px rgba(37,99,235,.18);
}

.field label{
  position:absolute;
  left:14px;
  top:50%;
  transform:translateY(-50%);
  font-size:14px;
  color:var(--muted);
  pointer-events:none;
  background:var(--card);
  padding:0 6px;
  transition:.2s ease;
}

.field input:focus + label,
.field input:not(:placeholder-shown) + label,
.field textarea:focus + label,
.field textarea:not(:placeholder-shown) + label{
  top:-8px;
  font-size:12px;
  color:var(--primary);
}


.contact-float button{
  width:100%;
  padding:14px;

  border:none;
  border-radius:12px;

  background:linear-gradient(
    135deg,
    var(--primary),
    var(--primary-dark)
  );

  color:#ffffff;
  font-size:15px;
  font-weight:600;
  cursor:pointer;

  transition:transform .15s ease, box-shadow .15s ease;
}

.contact-float button:hover{
  transform:translateY(-1px);
  box-shadow:0 12px 30px rgba(0,0,0,.2);
}

.contact-float button:active{
  transform:translateY(0);
  box-shadow:none;
}

Notes

  • Modern floating label UX
  • Improves clarity and readability
  • Business-friendly design

Preview styles shown. Production customization recommended.

Browse More UI Components

Explore hundreds of reusable HTML & CSS UI components built for modern web projects.
Discover buttons, cards, loaders, animations, layouts, and more all with live previews and clean, copy-paste code.

Leave a Reply

Your email address will not be published. Required fields are marked *