checkbox-custom-styles.md
ASCII text
title: Customize an HTML Checkbox
date: 2022 Feb 19
updated: 2024 Feb 1
---
TL;DR: appearance: none;.
Checkboxes are hard to style. But when you're making a website, they may look ugly.
As you can see here, this bland checkbox does not fit into my clearly great website(/s). But really, it does not fit in at all.
The first step toward styling it how we want it is to give it an appearance of none, and a width and height that are what you want.
input[type="checkbox"] {
appearance: none;
width: 15px;
height: 15px;
background-color: grey;
}
Now we can do whatever we want to it. You're also able to add a :checked sudo to change certain elements(like the background-color) depending on if the checkbox is checked or not.
input[type="checkbox"] {
appearance: none;
width: 15px;
height: 15px;
background: #555;
border: 1px #252525 solid;
border-radius: 2px;
}
input[type="checkbox"]:checked {
background: #ce5aff;
}
1
---
2
title: Customize an HTML Checkbox
3
date: 2022 Feb 19
4
updated: 2024 Feb 1
5
---
6
TL;DR: `appearance: none;`.
7
8
Checkboxes are hard to style. But when you're making a website, they may look ugly.
9
10
<input type="checkbox" style="appearance: checkbox;" />
11
12
As you can see here, this bland checkbox does not fit into my clearly great website(/s). But really, it does not fit in at all.
13
14
The first step toward styling it how we want it is to give it an appearance of none, and a width and height that are what you want.
15
16
```css
17
input[type="checkbox"] {
18
appearance: none;
19
width: 15px;
20
height: 15px;
21
background-color: grey;
22
}
23
```
24
25
<iframe src="/blog-files/checkbox-custom-styles-ex1.html" style="background: #fff; border: none"></iframe>
26
27
Now we can do whatever we want to it. You're also able to add a `:checked` sudo to change certain elements(like the `background-color`) depending on if the checkbox is checked or not.
28
29
```css
30
input[type="checkbox"] {
31
appearance: none;
32
width: 15px;
33
height: 15px;
34
background: #555;
35
border: 1px #252525 solid;
36
border-radius: 2px;
37
}
38
39
input[type="checkbox"]:checked {
40
background: #ce5aff;
41
}
42
```
43
44
<iframe src="/blog-files/checkbox-custom-styles-ex2.html" style="background: #fff; border: none"></iframe>
45