Simple CSS custom checkbox

checkbox custom style with css only

by Vishnuprasad ps

HTML

<label class="custom-checkbox">One
  <input type="checkbox" checked="checked">
  <span class="checkmark"></span>
</label>
<label class="custom-checkbox">Two
  <input type="checkbox">
  <span class="checkmark"></span>
</label>

CSS

body {
  background: #333;
  color: #fff;
}

.custom-checkbox {
  display: block;
  position: relative;
  padding-left: 35px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 22px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.custom-checkbox input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #fff;
  border-radius: 4px;
}

.custom-checkbox:hover input~.checkmark {
  background-color: #ccc;
}

.custom-checkbox input:checked~.checkmark {
  background-color: #1370c7;
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.custom-checkbox input:checked~.checkmark:after {
  display: block;
}

.custom-checkbox .checkmark:after {
  left: 9px;
  top: 5px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 3px 3px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}