# How to check if a checkbox is checked using JavaScript?

> Learn how to check whether a checkbox is checked in JavaScript by inspecting its checked property, and why you should not rely on getAttribute or value.

Author: Flavio Copes | Published: 2019-09-08 | Canonical: https://flaviocopes.com/how-to-check-checkbox-checked/

Inspect the `checked` property of the element.

Say you have this checkbox:

```html
<input type="checkbox" class="checkbox" />
```

You can see if it's checked using

```js
document.querySelector('.checkbox').checked
```

You can also check if looking for `.checkbox:checked` does not return `null`:

```js
document.querySelector('.checkbox:checked') !== null
```

but I think looking for `.checked` is cleaner.

Do NOT use `getAttribute()` looking for the `checked` attribute value, because that's always true if the checkbox is checked by default in this way:

```html
<input type="checkbox" checked />
```

Also don't check for the `value` of a checkbox element. It's always `on`, regardless whether the checkbox is checked or not.
