CSSCustom Checkboxes & Radios

Custom Checkboxes & Radio Buttons

Default checkbox and radio inputs are hard to style consistently across browsers. By hiding the native input and using ::before or ::after pseudo-elements, you can create custom styled checkboxes and radios that match your design while maintaining full accessibility.

Hiding default input, styling custom checkbox

CSS
<!-- HTML structure -->
<input type="checkbox" id="checkbox1" class="checkbox">
<label for="checkbox1">Accept terms</label>

<!-- Hide native checkbox -->
.checkbox {
  appearance: none;  /* removes default styling -->
  width: 20px;
  height: 20px;
  border: 2px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  margin: 0;
  vertical-align: middle;
  transition: all 0.3s ease;
}

.checkbox:hover {
  border-color: #999;
}

.checkbox:focus {
  outline: 2px solid blue;
  outline-offset: 2px;
}

.checkbox:checked {
  background: blue;
  border-color: blue;
}

/* Checkmark using ::after -->
.checkbox:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 14px;
  font-weight: bold;
}

<!-- Custom checkbox with checkmark -->

/* Label styling -->
label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

<!-- Label and input aligned -->
Custom radio button styling

CSS
<!-- HTML structure -->
<input type="radio" id="radio1" name="option" class="radio">
<label for="radio1">Option 1</label>

<!-- Custom radio styling -->
.radio {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #ccc;
  border-radius: 50%;  /* circular -->
  cursor: pointer;
  margin: 0;
  transition: all 0.3s ease;
}

.radio:hover {
  border-color: #999;
}

.radio:focus {
  outline: 2px solid blue;
  outline-offset: 2px;
}

.radio:checked {
  border-color: blue;
  box-shadow: inset 0 0 0 4px blue;
  /* Or use background -->
}

/* Dot indicator using ::before -->
.radio:checked::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: blue;
  border-radius: 50%;
}

<!-- Custom radio with dot -->
Advanced custom checkbox styles

CSS
<!-- Filled checkbox -->
.checkbox-filled {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #ccc;
  background: white;
  cursor: pointer;
  transition: all 0.3s;
}

.checkbox-filled:checked {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: #667eea;
}

<!-- Gradient fill on check -->

/* Toggle-style checkbox -->
.toggle {
  appearance: none;
  width: 50px;
  height: 28px;
  background: #ccc;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  transition: background 0.3s;
}

.toggle:checked {
  background: #4CAF50;
}

.toggle::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.3s;
}

.toggle:checked::after {
  left: 24px;
}

<!-- Toggle switch appearance -->

/* Rounded checkbox -->
.checkbox-rounded {
  appearance: none;
  width: 24px;
  height: 24px;
  border: 2px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  background: white;
  transition: all 0.2s;
}

.checkbox-rounded:checked {
  background: #3498db;
  border-color: #3498db;
  box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.checkbox-rounded:checked::after {
  content: '✓';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: white;
  font-weight: bold;
}

<!-- Rounded modern style -->
Group styling for checkboxes

CSS
<!-- Checkbox group -->
<div class="checkbox-group">
  <label class="checkbox-label">
    <input type="checkbox" class="checkbox">
    <span>Option 1</span>
  </label>
  <label class="checkbox-label">
    <input type="checkbox" class="checkbox">
    <span>Option 2</span>
  </label>
  <label class="checkbox-label">
    <input type="checkbox" class="checkbox">
    <span>Option 3</span>
  </label>
</div>

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.checkbox-label:hover {
  background: #f5f5f5;
}

.checkbox-label:has(input:checked) {
  background: #e3f2fd;
}

<!-- Highlight selected items -->

/* Radio group -->
.radio-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

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

<!-- Horizontal radio layout -->

/* Card-style checkbox -->
.checkbox-card {
  appearance: none;
  width: auto;
  padding: 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  background: white;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.checkbox-card:checked {
  border-color: #3498db;
  background: #e3f2fd;
}

.checkbox-card:checked::before {
  content: '✓';
  width: 24px;
  height: 24px;
  background: #3498db;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

<!-- Card selection style -->
Accessibility considerations

CSS
<!-- Keyboard focus visible -->
.checkbox:focus-visible {
  outline: 2px solid #4A90E2;
  outline-offset: 2px;
}

<!-- Always show focus for keyboard users -->

/* High contrast mode -->
@media (prefers-contrast: more) {
  .checkbox {
    border-width: 3px;
  }

  .checkbox:checked {
    box-shadow: 0 0 0 3px white, 0 0 0 6px #000;
  }
}

<!-- Respect contrast preferences -->

/* Disabled state -->
.checkbox:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: #ccc;
  background: #f5f5f5;
}

.checkbox:disabled + label {
  opacity: 0.5;
  cursor: not-allowed;
}

<!-- Visual indication of disabled state -->

/* Large touch target for mobile -->
.checkbox {
  width: 24px;
  height: 24px;
  min-width: 44px;
  min-height: 44px;
  /* Ensure 44px minimum touch target -->
}

<!-- Accessible on touch devices -->

/* Label properly associated -->
<input type="checkbox" id="unique-id" class="checkbox">
<label for="unique-id">Option</label>

<!-- Always use id/for association -->
Note
Custom checkboxes use `appearance: none` to hide native input, then style with border, background, and pseudo-elements. Create checkmarks with `::after` content. Always include focus states for keyboard accessibility, maintain proper label associations with id/for, and provide at least 44×44px touch targets on mobile.
Next
Custom select dropdowns: [Custom Select Menus](/css/custom-select).