- Home
- /
- Contact Form UI with Validation using HTML, CSS & JavaScript
Modern Contact Form UI with Validation | Soft Neumorphism Design using HTML, CSS & JavaScript
HTML
Contact Form UI
Contact Us
We'd love to hear from you! Fill out the form below to send us a message.
CSS
/* Reset & Base */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #e0e5ec;
font-family: 'Segoe UI', sans-serif;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.contact-container {
background: #e0e5ec;
padding: 40px;
border-radius: 20px;
width: 90%;
max-width: 500px;
text-align: center;
box-shadow: 10px 10px 30px #bebebe, -10px -10px 30px #ffffff;
}
.contact-container h2 {
color: #333;
margin-bottom: 10px;
}
.contact-container p {
color: #666;
margin-bottom: 20px;
}
/* Input Fields */
.input-group {
position: relative;
margin-bottom: 25px;
}
.input-group input,
.input-group textarea {
width: 100%;
padding: 14px 12px;
border: none;
border-radius: 12px;
background: #e0e5ec;
box-shadow: inset 5px 5px 10px #bebebe, inset -5px -5px 10px #ffffff;
font-size: 14px;
color: #333;
resize: none;
}
.input-group textarea {
height: 120px;
}
.input-group label {
position: absolute;
left: 12px;
top: 14px;
font-size: 14px;
color: #888;
pointer-events: none;
transition: 0.3s;
}
.input-group input:focus + label,
.input-group input:valid + label,
.input-group textarea:focus + label,
.input-group textarea:valid + label {
top: -10px;
left: 10px;
font-size: 12px;
background: #e0e5ec;
padding: 0 6px;
color: #333;
border: 1px solid #aaa;
border-radius: 4px;
}
/* Button */
button {
width: 100%;
padding: 12px;
border: none;
border-radius: 12px;
background: linear-gradient(to right, #6a11cb, #2575fc);
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background 0.3s;
}
button:hover {
background: linear-gradient(to right, #5b0dba, #1e5ddd);
}
/* Response */
.response-msg {
margin-top: 15px;
font-size: 14px;
color: #333;
}
JavaScript
const form = document.getElementById('contactForm');
const responseMsg = document.getElementById('responseMsg');
form.addEventListener('submit', function (e) {
e.preventDefault();
const name = document.getElementById('name');
const email = document.getElementById('email');
const message = document.getElementById('message');
if (name.value && email.value && message.value) {
responseMsg.textContent = "Message sent successfully!";
responseMsg.style.color = "#388e3c";
form.reset();
} else {
responseMsg.textContent = "Please fill all fields.";
responseMsg.style.color = "#d32f2f";
}
});