• 2020-03-14

    Custom CSS checkbox

    Comments

    Start a discussion

    <label>
      <input type="checkbox">
      <span>Checkbox</span>
    </label>
    span {
      display: flex;
      align-items: center;
    }
    
    span:before {
      content: '';
      height: 24px;
      width: 24px;
      background: #eee;
      display: block;
      margin-right: .5rem;
    }
    
    input {
      display: none;
    }
    
    label input:checked ~ span:before {
      background-color: blue;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='none' d='M0 0h24v24H0z'/%3E%3Cpath d='M10 15.172l9.192-9.193 1.415 1.414L10 18l-6.364-6.364 1.414-1.414z' fill='rgba(255,255,255,1)'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: center;
    }

    Sources