Contact Form Code Html Css Js

0



📩 Contact Form with Live Preview

A fully responsive contact form with HTML, CSS & JS. Copy each section easily using the buttons below.

🌐 1. HTML Code


<div class="contact-container">
  <h2>Get In Touch</h2>
  <form id="contactForm">
    <input type="text" id="name" placeholder="Your Name" required>
    <input type="email" id="email" placeholder="Your Email" required>
    <textarea id="message" placeholder="Your Message" required></textarea>
    <button type="submit">Send Message</button>
  </form>
  <p id="form-status"></p>
</div>
  

🎨 2. CSS Code


/* Contact Form CSS */
.contact-container {
  max-width: 400px;
  margin: 40px auto;
  background: #1e1e1e;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 0 15px rgba(255,255,255,0.1);
}
.contact-container h2 {
  text-align: center;
  margin-bottom: 20px;
}
.contact-container input,
.contact-container textarea {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  border: none;
  border-radius: 5px;
  outline: none;
  background: #161b22;
  color: white;
}
.contact-container button {
  width: 100%;
  background: #4caf50;
  color: white;
  padding: 12px;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
  transition: 0.3s;
}
.contact-container button:hover {
  background: #45a049;
}
#form-status {
  text-align: center;
  margin-top: 10px;
  font-weight: bold;
}
  

⚙️ 3. JavaScript Code


// Contact Form JS
document.getElementById('contactForm').addEventListener('submit', function(e) {
  e.preventDefault();
  const name = document.getElementById('name').value.trim();
  const email = document.getElementById('email').value.trim();
  const message = document.getElementById('message').value.trim();
  const status = document.getElementById('form-status');

  if (!name || !email || !message) {
    status.innerText = "⚠️ Please fill out all fields!";
    status.style.color = "orange";
    return;
  }

  // Simulate success
  status.innerText = "✅ Message Sent Successfully!";
  status.style.color = "#4caf50";
  this.reset();
});
  

👁️ Live Preview

Post a Comment

0Comments
Post a Comment (0)