HTML and CSS

Checkboxes

What does this CSS snippet do?

This CSS snippet styles custom circular checkboxes using hidden <input> elements and styled <label>s. Here’s a breakdown of how it works:

Key Features:

  • Hidden Input: The actual checkbox (input) is hidden (display: none), and the label handles the visual interaction.
  • Styled Label:
    • Acts like the checkbox surface.
    • Includes a circular box on the left created via ::before.
    • Contains text aligned to the right of the circle.
    • Uses dashed bottom border for a stylized look.
  • Circle Indicator (::before):
    • A 24x24px circle with a light border.
    • Positioned to the left of the label content.
    • When hovered or focused, the border becomes darker.
  • Checked State (input:checked + label):
    • Label color darkens.
    • The circle ::before displays a FontAwesome checkmark (\f00c) in the center.
    • Styled with a light background and bold black checkmark.

Visual Impression:

  • Minimalist, modern design using opacity and borders.
  • No default checkbox UI — fully custom.
  • FontAwesome required for the checkmark icon.
CSS
.col-checkbox input {
  display: none;
}

.col-checkbox label {
  display: block;
  position: relative;
  padding: 10px 20px 4px 40px;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.30);
  color: rgba(0, 0, 0, 0.30);
  cursor: pointer;
}

.col-checkbox label::before {
  content: '';
  display: block;
  position: absolute;
  top: 10px;
  left: 0;
  width: 24px;
  height: 24px;
  border: 2px solid rgba(0, 0, 0, 0.30);
  border-radius: 100%;
}

.col-checkbox label:hover, input:focus + label {
  border-bottom: 1px dashed rgb(0, 0, 0, 1.00);
  color: rgba(0, 0, 0, 1.00);
}

.col-checkbox label::before:hover {
  border: 2px solid rgba(0, 0, 0, 0.60);
  color: rgba(0, 0, 0, 1.00);
}

.col-checkbox label:hover::before {
  border: 2px solid rgba(0, 0, 0, 0.60);
} 

.col-checkbox input:checked + label {
  border-bottom: 1px dashed rgb(0, 0, 0, 1.00);
  color: rgba(0, 0, 0, 0.90);
}

.col-checkbox input:checked + label::before {
  position: absolute; 
  padding-top: 2px;
  padding-left: 4px;
  font-family: 'FontAwesome';
  font-size: 12px;
  content: '\f00c'; 
  background: rgba(255, 255, 255, 0.80);
  border: 2px solid rgba(0, 0, 0, 0.60);
  color: rgba(0, 0, 0, 1.00);
  font-weight: bold; 
}
HTML
<div class="container">

 <div class="row justify-content-between">

  <div class="col-md-3 col-checkbox">
   <input id="checkbox-01" type="checkbox">
   <label for="checkbox-01">Sunglasses</label>
  </div>

  <div class="col-md-3 col-checkbox">
   <input id="checkbox-02" type="checkbox">
   <label for="checkbox-02">Pencils</label>
  </div>

  <div class="col-md-3 col-checkbox">
   <input id="checkbox-03" type="checkbox">
   <label for="checkbox-03">Shoes</label>
  </div>

  <div class="col-md-3 col-checkbox">
   <input id="checkbox-04" type="checkbox">
   <label for="checkbox-04">Notepad</label>
  </div>

 </div>
</div>