contact-forms
intermediate
contact
form
validation
floating-labels
modern
Category · Forms Difficulty Level · Intermediate Published on · January 30, 2024

Modern Contact Form

Sleek contact form with floating labels, validation animations, and smooth transitions, perfect for professional websites.

#contact #form #validation #floating-labels #modern

Responsive Design

Yes

Dark Mode Support

No

lines

436

Browser Compatibility

Chrome · Firefox · Safari · Edge

Live Preview

Interact with the component without leaving the page.

450px

Overview

Sleek contact form with floating labels, validation animations, and smooth transitions, perfect for professional websites.

How to use

  1. Copy the HTML markup into your page.
  2. Paste the CSS into your stylesheet and ensure the selectors match your markup.
  3. Paste the JavaScript and load it after the markup.
  4. Adjust spacing, colors, and text to match your design system.

Customization tips

  • Rename class names to avoid collisions with your existing CSS.
  • Replace hard-coded colors with CSS variables for theming.
  • Verify the layout at 320px, 768px, and 1024px widths.

HTML

68

lines

CSS

257

lines

JavaScript

111

lines


                <div class="contact-form-container">
  <div class="form-header">
    <h2>Get In Touch</h2>
    <p>We'd love to hear from you. Send us a message and we'll respond as soon as possible.</p>
  </div>
  
  <form class="contact-form" id="contactForm">
    <div class="form-row">
      <div class="form-group">
        <input type="text" id="firstName" name="firstName" required>
        <label for="firstName">First Name</label>
        <span class="form-line"></span>
      </div>
      
      <div class="form-group">
        <input type="text" id="lastName" name="lastName" required>
        <label for="lastName">Last Name</label>
        <span class="form-line"></span>
      </div>
    </div>
    
    <div class="form-group">
      <input type="email" id="email" name="email" required>
      <label for="email">Email Address</label>
      <span class="form-line"></span>
      <span class="error-message" id="emailError"></span>
    </div>
    
    <div class="form-group">
      <input type="tel" id="phone" name="phone">
      <label for="phone">Phone Number (Optional)</label>
      <span class="form-line"></span>
    </div>
    
    <div class="form-group">
      <select id="subject" name="subject" required>
        <option value=""></option>
        <option value="general">General Inquiry</option>
        <option value="support">Support</option>
        <option value="business">Business Partnership</option>
        <option value="other">Other</option>
      </select>
      <label for="subject">Subject</label>
      <span class="form-line"></span>
    </div>
    
    <div class="form-group">
      <textarea id="message" name="message" rows="5" required></textarea>
      <label for="message">Message</label>
      <span class="form-line"></span>
    </div>
    
    <div class="form-group checkbox-group">
      <input type="checkbox" id="newsletter" name="newsletter">
      <label for="newsletter" class="checkbox-label">
        <span class="checkbox-custom"></span>
        Subscribe to our newsletter for updates
      </label>
    </div>
    
    <button type="submit" class="submit-btn">
      <span class="btn-text">Send Message</span>
      <span class="btn-loader">
        <span class="spinner"></span>
      </span>
    </button>
  </form>
</div>

              
68lines
2275characters
HTMLLanguage

Browser Compatibility

Chrome

>= 50

Firefox

>= 45

Safari

>= 10

Edge

>= 15

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library ->