How to set checkbox size in HTML/CSS?

The checkbox is an HTML element which is used to take input from the user.
Method 1: The checkbox size can be set by using height and width property. The height property sets the height of checkbox and width property sets the width of the checkbox.

Syntax:

input./*checkbox class name*/ {
    width : /*desired width*/;
    height : /*desired height*/;
}

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html>
  
<head>
    <title>
        Set checkbox size
    </title>
      
    <!-- Style to set the size of checkbox -->
    <style>
        input.largerCheckbox {
            width: 40px;
            height: 40px;
        }
    </style>
</head>
  
<body
    <input type="checkbox" class="defaultCheckbox"
            name="checkBox1" checked>
          
    <input type="checkbox" class="largerCheckbox"
            name="checkBox2" checked>
</body>
  
</html>                    

chevron_right


Output:

Note: This works well for Google Chrome, Microsoft Edge and Internet Explorer. In Mozilla Firefox the clickable checkbox area is as specified but it displays a checkbox of the default size.

Method 2: An alternate solution that works for Mozilla Firefox as well is by using transform property.

Syntax:

input./*checkbox class name*/ {
    transform : scale(/*desired magnification*/);
}

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html>
  
<head>
    <title>
        Set the size of checkbox
    </title>
      
    <!-- Use transform scale property to 
        set size of checkbox -->
    <style>
        input.largerCheckbox {
            transform : scale(10);
        }
        body {
            text-align:center;
            margin-top:100px;
        }
    </style>
</head>
  
<body>
    <input type="checkbox" class="largerCheckbox"
            name="checkBox2" checked>
</body>
  
</html>

chevron_right


Output:

This method has a few drawbacks. The checkbox has to be positioned carefully to keep it within the browser window or prevent it from overlapping with other elements. Also, in some browsers, the checkbox may appear pixelated for larger sizes.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.