Блог

css Переключатель (toggle) для input checkbox
16 марта 2024 г.

Переключатель (toggle) для input checkbox

html css

Просто накидываем стили для <input>.

HTML

<input type="checkbox">

SCSS

html,body {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

input {

  &[type="checkbox"] {
    position: relative;
    width: 80px;
    height: 40px;
    background: #ccc;
    outline: none;
    border-radius: 20px;
    appearance: none;

    &:before {
      content: '';
      position: absolute;
      width: 36px;
      height: 36px;
      border-radius: 20px;
      top: 2px;
      left: 2px;
      background: #fff;
      transition: .2s;
    }

    &:checked {
      background: #03a9f4;

      &:before {
        left: 42px;
      }
    }
  }
}

Демонстрация