loader

Loading

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup

Getting Started with CSS

Quick StartCSS FAQs

Styling Properties

CSS ColorsCSS BackgroundsCSS BordersCSS Box ModelCSS MarginCSS PaddingCSS Size PropertiesCSS Text StylingCSS FontsCSS LinksCSS Hover EffectsCSS List StylesCSS ImagesCSS ButtonsCSS FormsCSS CursorsCSS PositioningCSS FloatCSS OverflowCSS Z-IndexCSS CombinatorsCSS Pseudo-ClassesCSS !importantCSS Math FunctionsCSS Navigation BarCSS Video Embedding

Advanced Techniques

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup
TutorialsCSS TutorialPropertiesCSS Forms

CSS Forms

Master CSS form styling to create beautiful, user-friendly forms with proper validation states and accessibility.

Well-styled forms improve user experience and conversion rates. CSS provides powerful tools for creating attractive, functional forms.

Input Styling

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
  transition: border-color 0.3s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 8px rgba(0, 123, 255, 0.3);
}

Form Layout

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

Validation States

input:valid {
  border-color: #28a745;
}

input:invalid:not(:focus):not(:placeholder-shown) {
  border-color: #dc3545;
}

.error-message {
  color: #dc3545;
  font-size: 14px;
  margin-top: 5px;
  display: none;
}

input:invalid:not(:focus):not(:placeholder-shown) + .error-message {
  display: block;
}

Checkbox and Radio

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.checkbox-label,
.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

Custom Checkbox

.custom-checkbox {
  position: relative;
  padding-left: 30px;
  cursor: pointer;
}

.custom-checkbox input {
  position: absolute;
  opacity: 0;
}

.custom-checkbox .checkmark {
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  border: 2px solid #ddd;
  border-radius: 4px;
}

.custom-checkbox input:checked + .checkmark {
  background-color: #007bff;
  border-color: #007bff;
}

.custom-checkbox input:checked + .checkmark::after {
  content: "✓";
  position: absolute;
  color: white;
  font-size: 14px;
  top: -2px;
  left: 3px;
}

Select Styling

select {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
  background-color: white;
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: #007bff;
}

Textarea

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
}

Disabled State

input:disabled,
select:disabled,
textarea:disabled {
  background-color: #e9ecef;
  cursor: not-allowed;
  opacity: 0.6;
}

Placeholder Styling

::placeholder {
  color: #6c757d;
  opacity: 1;
}

input:focus::placeholder {
  opacity: 0.5;
}

Submit Button

button[type="submit"],
input[type="submit"] {
  padding: 12px 24px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button[type="submit"]:hover {
  background-color: #0056b3;
}

button[type="submit"]:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
}

File Input

input[type="file"] {
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  padding: 8px 16px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 10px;
}

Search Input

input[type="search"] {
  padding: 10px 40px 10px 15px;
  border-radius: 20px;
  background-image: url("search-icon.svg");
  background-repeat: no-repeat;
  background-position: right 15px center;
}

Form Groups

.form-inline {
  display: flex;
  gap: 10px;
  align-items: center;
}

.form-inline input {
  flex: 1;
}

Floating Labels

.floating-label {
  position: relative;
}

.floating-label input {
  padding-top: 20px;
}

.floating-label label {
  position: absolute;
  top: 12px;
  left: 12px;
  transition: all 0.3s ease;
  pointer-events: none;
}

.floating-label input:focus + label,
.floating-label input:not(:placeholder-shown) + label {
  top: 2px;
  font-size: 12px;
  color: #007bff;
}

Best Practices

Form Best Practices

  • Use labels for all inputs - Provide clear validation feedback - Style focus states for accessibility - Use appropriate input types - Maintain consistent spacing - Make buttons large enough to tap (44x44px) - Show loading states - Disable submit during processing - Test on mobile devices - Ensure sufficient color contrast

Accessibility

/* Ensure labels are visible */
label {
  display: block;
  margin-bottom: 5px;
}

/* Clear focus states */
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Error states */
input[aria-invalid="true"] {
  border-color: #dc3545;
}

Master form styling to create user-friendly, accessible forms that convert!

How is this guide?

March 7th, 2026

CSS Buttons

Master CSS button styling to create beautiful, interactive buttons with hover effects, animations, and modern designs.

CSS Cursors

Master CSS cursor property to provide visual feedback and improve user experience with custom mouse cursors.

© 2026CoderrShyamAll Rights Reserved.

On this page

Input Styling
Form Layout
Validation States
Checkbox and Radio
Custom Checkbox
Select Styling
Textarea
Disabled State
Placeholder Styling
Submit Button
File Input
Search Input
Form Groups
Floating Labels
Best Practices
Accessibility
Follow us on GitHub