In this article, we will be learning how to make a custom design of the checkbox and radio button with animation using CSS only.

First, you need to create the following HTML structure.

<!DOCTYPE html>
<html>
<body>

  <h1>Custom Checkboxes</h1>
  <input type="checkbox" id="check1" class="checkinput" checked="checked">
  <label class="checkmark" for="check1">CheckBox One </label>

  <input type="checkbox" id="check2" class="checkinput">
  <label class="checkmark" for="check2">CheckBox Two </label>

  <input type="checkbox" id="check3" class="checkinput">
  <label class="checkmark" for="check3">CheckBox Three </label>

  <h1>Custom Radio Button</h1>
  <input type="radio" id="radio1" name="radiodesign" class="checkinput">
  <label class="radiobox" for="radio1">Radio One </label>

  <input type="radio" id="radio2" name="radiodesign" class="checkinput">
  <label class="radiobox" for="radio2">Radio Two</label>

  <input type="radio" id="radio3" name="radiodesign" class="checkinput">
  <label class="radiobox" for="radio3">Radio Three</label>

</body>
</html>

And then you need to apply below CSS In head tag or CSS file

<style>
  .checkmark,.radiobox{
    display: inline-block;
    position: relative;
    padding-left: 25px;
    height: 20px;
    margin-bottom: 5px;
  }
  /*For lable before box*/
  .checkmark:before,.radiobox:before{
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 16px;
    border: 2px solid #397DC2;
  }

  .radiobox:before{
    border-radius: 50%;
  }
  /*For red diamond shape*/
  .checkmark:after,.radiobox:after{
    position: absolute;
    height: 15px;
    width: 15px;
    background-color: #397DC2;
  }
  .radiobox:after{
    position: absolute;
    top: 5px;
    left: 5px;
    height: 10px;
    width: 10px;
    background-color: #397DC2;
  }
  
  /*For hide default checkbox*/
  input.checkinput{
    display: none;
  }
  /*For show diamond with animation*/
  input:checked + .checkmark:after{
    -webkit-animation:checkboxIn 0.3s infinite;
    -moz-animation:checkboxIn 0.3s infinite;
    -ms-animation:checkboxIn 0.3s infinite;
    -o-animation:checkboxIn 0.3s infinite;
    animation: checkboxIn 0.3s infinite;
    animation-iteration-count:1;
    animation-fill-mode: forwards;
    content: '';
  }
  input:checked + .radiobox:after{
    -webkit-animation:radioboxIn 0.3s infinite;
    -moz-animation:radioboxIn 0.3s infinite;
    -ms-animation:radioboxIn 0.3s infinite;
    -o-animation:radioboxIn 0.3s infinite;
    animation: radioboxIn 0.3s infinite;
    animation-iteration-count:1;
    animation-fill-mode: forwards;
    content: '';
  }

  /*Animation KeyFram needed for animation*/
  @keyframes checkboxIn{
    from {
      top: 0px;
      left: 0px;
    }
    to{
      top: 5px;
      left: 5px;
      height: 10px;
      width: 10px;
      -webkit-transform: rotate(45deg);
      -ms-transform: rotate(45deg);
      transform: rotate(45deg);
    }
  }
  @keyframes radioboxIn{
    from {
      -webkit-transform: rotate(0);
      -ms-transform: rotate(0);
      transform: rotate(0);
    }
    to{
      -webkit-transform: rotate(315deg);
      -ms-transform: rotate(315deg);
      transform: rotate(315deg);
    }
  }

</style>

Now you get the following result.

Subscribe

Select Categories