gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Create a stylish contact form using HTML, CSS, and JS.
- User
Create a stylish contact form using HTML, CSS, and JS.
- Assistant
Create a stylish contact form using HTML, CSS, and JS.
Creating a stylish contact form can enhance user experience and engagement on your website. Below is an example of how you might create a simple yet stylish contact form using HTML, CSS, and JavaScript. This example includes some simple validation to ensure that the form is filled out correctly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stylish Contact Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<form id="contactForm">
<h2>Contact Us</h2>
<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="Your name" required>
<label for="email">Email</label>
<input type="email" id="email" name="email" placeholder="Your email" required>
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Your message" required></textarea>
<button type="submit">Submit</button>
<p id="successMessage" style="display:none;">Thank you for contacting us!</p>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
body {
font-family: 'Arial', sans-serif;
background: #f4f4f9;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background: #fff;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 30px;
max-width: 400px;
width: 100%;
border-radius: 8px;
}
form h2 {
margin: 0 0 15px;
font-size: 24px;
color: #333;
}
form label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
form input[type="text"],
form input[type="email"],
form textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
form textarea {
height: 100px;
}
form button {
background: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background 0.3s ease;
}
form button:hover {
background: #0056b3;
}
#successMessage {
color: #28a745;
font-weight: bold;
text-align: center;
margin-top: 15px;
}
document.getElementById('contactForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
// Simple form validation
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const message = document.getElementById('message').value.trim();
if (name && email && message) {
// In a real-world scenario you would submit the form data to the server here
document.getElementById('successMessage').style.display = 'block';
// Reset the form
document.getElementById('contactForm').reset();
}
});
You should modify the JavaScript to handle actual submission logic and integrate it into a backend system for processing the form data in a real-world application.
Not yet included in a published release.