Animating a checkbox with CSS

Animating the checkboxes in your forms can greatly improve the experience your users have and will undeniably increase their desire to fill them in. A form that's more fun to fill in is a form that your users will fill in more often. In this article, we'll look at how to animate a checkbox using CSS!
•
Updated on August 14, 2026
•
3 min read
Believemy logo

Animating checkboxes in your forms can greatly enhance the experience your users will have and undeniably increase their desire to fill them out. A more enjoyable form to complete is a form that your users will fill out more often. In this article, let's see how to animate a checkbox with CSS!

Image

 

Step 1

The HTML code

HTML
<label class="checkbox">
      <input class="checkbox_input" type="checkbox">
      <svg class="checkbox_check" width="25" 
    height="25">
        <polyline points="20 6 9 17 4 12"></polyline>
      </svg>
    </label>
    
    <!-- ICON SCRIPT -->
    <script src="https://unpkg.com/feather-icons"></script>
    <script>
      feather.replace();
    </script>

In the previous step, we used two rather original tags: svg and polyline.

The svg tag allows you to create a new SVG shape, which is a mathematical representation of an image.

The polyline tag precisely defines the points of the SVG shape. Once connected, these points create a checkmark shape.

 

Step 2

Let's style the label and the checkbox.

CSS
.checkbox {
      cursor: pointer;
    }
    
    .checkbox:hover .checkbox_check {
      background: #ff4754;
    }
    
    .checkbox_input {
      width: 0;
      height: 0;
      opacity: 0;
    }

In the previous step, we hid the checkbox by the default created by our browser with the input tag.

We want to display our custom checkbox without any part. Thanks to the label tag, once we click on our custom checkbox, the actual checkbox that we just hid will be checked.

 

Step 3

Let's move on to styling the checkbox when it is checked!

CSS
.checkbox_input:checked + .checkbox_check {
      background: #ff4754;
      stroke-dashoffset: 0;
    }

The stroke-dashoffset property allows you to offset the SVG shape we just created. Here, we set it to its initial position: 0. So, we see the shape.

 

Step 4

Now, let's style the checkbox that we have created from scratch.

CSS
.checkbox_check {
      border: 0.2rem solid #ff4754;
      stroke: #f9f9f9;
      stroke-dasharray: 25;
      stroke-dashoffset: 25;
      stroke-linecap: round;
      stroke-width: 0.2em;
      border-radius: 0.2em;
      fill: none;
      transition: background 0.4s, stroke-dashoffset 
    0.6s;
    }

In the previous step, we used several properties that might overwhelm you a bit. However, you will see that everything is very simple, just keep in mind that we are styling our unchecked checkbox.

  • stroke: the color of the SVG shape
  • stroke-dasharray: the size of the shape (if we simplify a lot)
  • stroke-dashoffset: the offset of the SVG shape, here we hide it because it is 25px. So, we offset it by 25px: we don't see it.
  • stroke-linecap: the style of the line we created (our SVG shape is just a line, here we ask for it to be rounded on the sides)
  • stroke-width: the thickness of the shape's line
  • fill: the fill color of the shape
Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Create an animated 3D button using CSS

In this article, we'll find out how to create a three-dimensional button that will add a touch of softness and perspective to your projects!

December 9, 2024

Creating an animated list with CSS

Let's find out how to create an animated hover list!

December 9, 2024

Creating a button with a "fill" effect using CSS

In this article, we'll be taking a look at the secret to achieving this "filling" effect on a button!

December 9, 2024

Creating a glassmorphic connection form in HTML and CSS

In this article, we're going to create a form with a glassmorphic design. Modern effect guaranteed!

December 9, 2024

Create an animated "rainbow" button with CSS

In this article, we'll show you how to create a rainbow button that comes to life when the mouse hovers over it. A modern and sensational effect guaranteed!

December 9, 2024

Creating a cascading animation on text

For a slogan or for an animation on a very important page of your project, this very modern effect is also very easy to achieve. Let's take a look at how to do it in this article.

December 9, 2024

Creating a form with dynamic labels

The more modern a form, the more engaging it is. In this article, we'll look at how to create a form with dynamic labels that will increase the engagement of your forms and make your users want to fill them in.

December 9, 2024

Creating animated presentation cards with JavaScript

Whether you're presenting the team behind your project or anything else, using animated presentation cards will give your page a successful finishing touch. Find out how in this article!

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.