![]() |
In this article, we will learn whether it is possible to make checkboxes readonly in HTML or not. Checkboxes are commonly used to allow users to select multiple options from a set of choices. They are represented in HTML by the <input> tag with the type=”checkbox” attribute. It is not possible to set checkboxes to read-only using standard HTML attributes. However, there are alternative approaches such as using the disabled attribute or CSS properties like pointer-events that can simulate the read-only behavior for checkboxes. By using these approaches, you can achieve the same effect as read-only checkboxes. Table of Content Using disabled optionThis approach uses the disabled option with the input tag which represents the checkboxes. When the disabled option is added to the input tag, the checkbox is essentially disabled so you can view the checkbox but cannot interact with it. You can also use the ‘checked’ option and get the read-only checkbox which is already checked but cannot be unchecked. Syntax:<input name=".." type="checkbox" disabled value="1" />
Used Checkbox options:
Example: In this example we will see the the implementation to make the checkboxes readonly using the disabled option HTML
Output: Using onclick methodThis approach is using the onclick method with the input tag which is representing the checkboxes. When the on-click method is added to the input tag, and it is set to a “return false” value the checkbox is essentially disabled so you can view the checkbox but cannot interact with it. Syntax:<input type="checkbox" onclick="return false"/>
Used method:
Example: In this example we will see the implementation of how to make the checkboxes read-only using the onclick method. HTML
Output: Using the pointer-events propertyThis approach is using the pointer-events CSS property to the input tag which is representing the checkboxes. When this CSS property is given as design to the input tag, the checkbox is essentially read-only so you can view the checkbox but cannot interact with it. Syntax:input[type="checkbox"]{ Used Property:
Example: In this example we will see how to make the checkboxes readonly using the pointer-events property: HTML
Output: |
Reffered: https://www.geeksforgeeks.org
HTML |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |