HTML Form Styling
Making forms look beautiful with CSS
🎨 What is Form Styling?
Form styling uses CSS to make HTML forms look attractive and user-friendly. You can change colors, fonts, spacing, and layout to create professional-looking forms.
<!-- Basic form with inline styling -->
<form style="padding: 20px; border: 1px solid #ccc;">
<input type="text" style="padding: 10px; border: 1px solid #ddd;">
</form>
Basic Form Styling
Input Fields
Style text inputs and textareas
Buttons
Create attractive submit buttons
Layout
Organize form elements nicely
Focus States
Highlight active form fields
🔹 Styling Input Fields
Make input fields look professional:
<style>
.styled-input {
width: 100%;
padding: 12px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 16px;
margin-bottom: 10px;
}
.styled-input:focus {
border-color: #007cba;
outline: none;
}
</style>
<form>
<input type="text" class="styled-input" placeholder="Your name">
<input type="email" class="styled-input" placeholder="Your email">
</form>
Output:
🔹 Styling Buttons
Create attractive form buttons:
<style>
.btn-primary {
background-color: #007cba;
color: white;
padding: 12px 24px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
.btn-primary:hover {
background-color: #005a87;
}
</style>
<button type="submit" class="btn-primary">Submit Form</button>
<button type="reset" class="btn-secondary">Reset</button>
Output:
🔹 Form Layout
Organize form elements with CSS Grid or Flexbox:
<style>
.form-container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
.form-group {
margin-bottom: 15px;
}
.form-label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
</style>
<div class="form-container">
<div class="form-group">
<label class="form-label">Name:</label>
<input type="text" class="styled-input">
</div>
<div class="form-group">
<label class="form-label">Email:</label>
<input type="email" class="styled-input">
</div>
</div>
Output:
🔹 Complete Styled Form
A complete example with all styling:
<style>
.contact-form {
max-width: 500px;
margin: 20px auto;
padding: 30px;
background: #f9f9f9;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.form-title {
text-align: center;
color: #333;
margin-bottom: 20px;
}
</style>
<form class="contact-form">
<h2 class="form-title">Contact Us</h2>
<div class="form-group">
<label>Full Name:</label>
<input type="text" required>
</div>
<div class="form-group">
<label>Message:</label>
<textarea rows="4"></textarea>
</div>
<button type="submit">Send Message</button>
</form>