How to make a checkbox read only with HTML and JavaScript?

Sometimes, we want to make a checkbox read only with HTML and JavaScript.

In this article, we’ll look at how to make a checkbox read only with HTML and JavaScript.

How to make a checkbox read only with HTML and JavaScript?

To make a checkbox read only with HTML and JavaScript, we return false when we click on the checkbox.

For instance, we write

<input type="checkbox" onclick="return false" />

to set onclick to return false` to stop clicks from modifying the checkbox’s state.

Conclusion

To make a checkbox read only with HTML and JavaScript, we return false when we click on the checkbox.