contact-forms
intermediate
contact
form
validation
upload
responsive
animation
Category · Forms Difficulty Level · Intermediate Published on · August 18, 2025

Contact Form

Modern contact form with validation, animations, file upload, and success/error states.

#contact #form #validation #upload #responsive #animation

Responsive Design

Yes

Dark Mode Support

No

lines

1014

Browser Compatibility

Chrome · Firefox · Safari · Edge

Live Preview

Interact with the component without leaving the page.

700px

Overview

Modern contact form with validation, animations, file upload, and success/error states.

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

186

lines

CSS

524

lines

JavaScript

304

lines


                <div class="contact-container">
  <div class="contact-header">
    <h1 class="contact-title">Get In Touch</h1>
    <p class="contact-subtitle">We'd love to hear from you. Send us a message and we'll respond as soon as possible.</p>
  </div>
  
  <div class="contact-content">
    
    <div class="contact-info">
      <div class="info-item">
        <div class="info-icon">
          <svg viewBox="0 0 24 24" fill="currentColor">
            <path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/>
          </svg>
        </div>
        <div class="info-content">
          <h3>Address</h3>
          <p>123 Business Street<br>Suite 100<br>New York, NY 10001</p>
        </div>
      </div>
      
      <div class="info-item">
        <div class="info-icon">
          <svg viewBox="0 0 24 24" fill="currentColor">
            <path d="M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"/>
          </svg>
        </div>
        <div class="info-content">
          <h3>Phone</h3>
          <p>+1 (555) 123-4567<br>Mon-Fri 9AM-6PM EST</p>
        </div>
      </div>
      
      <div class="info-item">
        <div class="info-icon">
          <svg viewBox="0 0 24 24" fill="currentColor">
            <path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/>
          </svg>
        </div>
        <div class="info-content">
          <h3>Email</h3>
          <p>hello@company.com<br>support@company.com</p>
        </div>
      </div>
      
      <div class="social-links">
        <h3>Follow Us</h3>
        <div class="social-icons">
          <a href="#" class="social-link">
            <svg viewBox="0 0 24 24" fill="currentColor">
              <path d="M24 4.557c-.883.392-1.832.656-2.828.775 1.017-.609 1.798-1.574 2.165-2.724-.951.564-2.005.974-3.127 1.195-.897-.957-2.178-1.555-3.594-1.555-3.179 0-5.515 2.966-4.797 6.045-4.091-.205-7.719-2.165-10.148-5.144-1.29 2.213-.669 5.108 1.523 6.574-.806-.026-1.566-.247-2.229-.616-.054 2.281 1.581 4.415 3.949 4.89-.693.188-1.452.232-2.224.084.626 1.956 2.444 3.379 4.6 3.419-2.07 1.623-4.678 2.348-7.29 2.04 2.179 1.397 4.768 2.212 7.548 2.212 9.142 0 14.307-7.721 13.995-14.646.962-.695 1.797-1.562 2.457-2.549z"/>
            </svg>
          </a>
          <a href="#" class="social-link">
            <svg viewBox="0 0 24 24" fill="currentColor">
              <path d="M22.46 6c-.77.35-1.6.58-2.46.69.88-.53 1.56-1.37 1.88-2.38-.83.5-1.75.85-2.72 1.05C18.37 4.5 17.26 4 16 4c-2.35 0-4.27 1.92-4.27 4.29 0 .34.04.67.11.98C8.28 9.09 5.11 7.38 3 4.79c-.37.63-.58 1.37-.58 2.15 0 1.49.75 2.81 1.91 3.56-.71 0-1.37-.2-1.95-.5v.03c0 2.08 1.48 3.82 3.44 4.21a4.22 4.22 0 0 1-1.93.07 4.28 4.28 0 0 0 4 2.98 8.521 8.521 0 0 1-5.33 1.84c-.34 0-.68-.02-1.02-.06C3.44 20.29 5.7 21 8.12 21 16 21 20.33 14.46 20.33 8.79c0-.19 0-.37-.01-.56.84-.6 1.56-1.36 2.14-2.23z"/>
            </svg>
          </a>
          <a href="#" class="social-link">
            <svg viewBox="0 0 24 24" fill="currentColor">
              <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
            </svg>
          </a>
        </div>
      </div>
    </div>
    
    
    <div class="contact-form-wrapper">
      <form class="contact-form" id="contactForm">
        <div class="form-row">
          <div class="form-group">
            <label for="firstName" class="form-label">First Name *</label>
            <input type="text" id="firstName" name="firstName" class="form-input" required>
            <span class="form-error" id="firstNameError"></span>
          </div>
          
          <div class="form-group">
            <label for="lastName" class="form-label">Last Name *</label>
            <input type="text" id="lastName" name="lastName" class="form-input" required>
            <span class="form-error" id="lastNameError"></span>
          </div>
        </div>
        
        <div class="form-group">
          <label for="email" class="form-label">Email Address *</label>
          <input type="email" id="email" name="email" class="form-input" required>
          <span class="form-error" id="emailError"></span>
        </div>
        
        <div class="form-group">
          <label for="phone" class="form-label">Phone Number</label>
          <input type="tel" id="phone" name="phone" class="form-input">
          <span class="form-error" id="phoneError"></span>
        </div>
        
        <div class="form-group">
          <label for="subject" class="form-label">Subject *</label>
          <select id="subject" name="subject" class="form-select" required>
            <option value="">Select a subject</option>
            <option value="general">General Inquiry</option>
            <option value="support">Technical Support</option>
            <option value="sales">Sales Question</option>
            <option value="partnership">Partnership</option>
            <option value="other">Other</option>
          </select>
          <span class="form-error" id="subjectError"></span>
        </div>
        
        <div class="form-group">
          <label for="message" class="form-label">Message *</label>
          <textarea id="message" name="message" class="form-textarea" rows="5" placeholder="Tell us more about your inquiry..." required></textarea>
          <span class="form-error" id="messageError"></span>
          <div class="character-count">
            <span id="charCount">0</span>/500 characters
          </div>
        </div>
        
        <div class="form-group">
          <label class="file-upload-label">
            <input type="file" id="attachment" name="attachment" class="file-input" multiple accept=".pdf,.doc,.docx,.txt,.jpg,.png">
            <div class="file-upload-area" id="fileUploadArea">
              <svg class="upload-icon" viewBox="0 0 24 24" fill="currentColor">
                <path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" />
              </svg>
              <span class="upload-text">Drop files here or click to upload</span>
              <span class="upload-hint">PDF, DOC, TXT, JPG, PNG (Max 5MB each)</span>
            </div>
          </label>
          <div class="uploaded-files" id="uploadedFiles"></div>
        </div>
        
        <div class="form-group checkbox-group">
          <label class="checkbox-label">
            <input type="checkbox" id="newsletter" name="newsletter" class="checkbox-input">
            <span class="checkbox-custom"></span>
            <span class="checkbox-text">Subscribe to our newsletter for updates and news</span>
          </label>
        </div>
        
        <div class="form-group checkbox-group">
          <label class="checkbox-label">
            <input type="checkbox" id="privacy" name="privacy" class="checkbox-input" required>
            <span class="checkbox-custom"></span>
            <span class="checkbox-text">I agree to the <a href="#" class="privacy-link">Privacy Policy</a> and <a href="#" class="privacy-link">Terms of Service</a> *</span>
          </label>
          <span class="form-error" id="privacyError"></span>
        </div>
        
        <button type="submit" class="submit-btn" id="submitBtn">
          <span class="btn-text">Send Message</span>
          <span class="btn-loading" style="display: none;">
            <svg class="loading-spinner" viewBox="0 0 24 24">
              <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-dasharray="32" stroke-dashoffset="32">
                <animate attributeName="stroke-dasharray" dur="2s" values="0 32;16 16;0 32;0 32" repeatCount="indefinite"/>
                <animate attributeName="stroke-dashoffset" dur="2s" values="0;-16;-32;-32" repeatCount="indefinite"/>
              </circle>
            </svg>
            Sending...
          </span>
        </button>
      </form>
      
      
      <div class="form-message success-message" id="successMessage" style="display: none;">
        <svg class="message-icon" viewBox="0 0 24 24" fill="currentColor">
          <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
        </svg>
        <div class="message-content">
          <h3>Message Sent Successfully!</h3>
          <p>Thank you for contacting us. We'll get back to you within 24 hours.</p>
        </div>
      </div>
      
      <div class="form-message error-message" id="errorMessage" style="display: none;">
        <svg class="message-icon" viewBox="0 0 24 24" fill="currentColor">
          <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
        </svg>
        <div class="message-content">
          <h3>Error Sending Message</h3>
          <p>There was an error sending your message. Please try again or contact us directly.</p>
        </div>
      </div>
    </div>
  </div>
</div>

              
186lines
9760characters
HTMLLanguage

Browser Compatibility

Chrome

>= 60

Firefox

>= 55

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 ->