
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM checked Property
The HTML DOM checked property is used to set (update) or get (retrieve) the checked status of a checkbox field. It returns a boolean value: "true" if the checkbox is checked, and "false" otherwise.
In HTML, "checkbox" is an input field type that belongs to HTML forms, specified with type = "checkbox". It allows users to select multiple preferences when filling out a form.
Syntax
Following is the syntax of the HTML DOM checked (to get the checked property) property −
checkboxObject.checked
To update (set) the checked property, use the following syntax −
checkboxObject.checked = true|false
Parameters
Since it is a property, it does not accept any parameters.
Return value
This property returns a boolean value (either true or false) representing whether the checkbox is checked.
Example 1
If the checkbox field is checked, it returns "true".
The following is the basic example of the HTML DOM checked property −
<!DOCTYPE html> <html> <head> <title>HTML DOM checked</title> </head> <body> <label for="">Checkbox Field:</label> <input type="checkbox" id="my_checkbox" checked> <p>Click the below button to check the checkbox field checked status.</p> <button id="check_btn">Check Status</button> <p id="result"></p> <script> document.getElementById("check_btn").addEventListener("click", ()=>{ let status = document.getElementById("my_checkbox").checked; document.getElementById("result").innerHTML = "The checkbox field checked status: " + status; }); </script> </body> </html>
Example 2
If the checkbox field is unchecked, it returns "false".
Following is another example of the HTML DOM checked property. We use this property to check whether the checkbox field is checked or not −
<!DOCTYPE html> <html> <head> <title>HTML DOM checked</title> </head> <body> <label for="">Checkbox Field:</label> <input type="checkbox" id="my_checkbox"> <p>Click the below button to check the checkbox field checked status.</p> <button id="check_btn">Check Status</button> <p id="result"></p> <script> document.getElementById("check_btn").addEventListener("click", ()=>{ let status = document.getElementById("my_checkbox").checked; document.getElementById("result").innerHTML = "The checkbox field checked status: " + status; }); </script> </body> </html>
Example 3: Updating the checkbox field status
In the example below, we use the checked property to update the current checked status of the checkbox field from "true" to "false" −
<!DOCTYPE html> <html> <head> <title>HTML DOM checked</title> </head> <body> <label for="">Checkbox Field:</label> <input type="checkbox" id="my_checkbox"> <p>Click the below button to update the checkbox field.</p> <button id="check_btn">Update Status</button> <p id="result"></p> <script> document.getElementById("check_btn").addEventListener("click", ()=>{ let status = document.getElementById("my_checkbox"); status.checked = true; document.getElementById("result").innerHTML = "Status updated to true"; }); </script> </body> </html>
Example 4: Toggle between Light and Dark Mode
The following example shows how to use the checked property to switch between light and dark modes by checking and unchecking the checkbox field −
<!DOCTYPE html> <html> <head> <title>HTML DOM checked</title> <style> div{ width: 200px; height: 200px; border: 1px solid green; border-radius: 10px; padding: 10px; text-align: center; justify-content: center; align-items: center; display: flex; font-family: sans-serif; font-weight: bold; margin: 5px 0px; transition: background-color 0.5s, color 0.5s; } </style> </head> <body> <p>Checked and unchecked the checkbox to switch between dark and light mode.</p> <input type="checkbox" id="my_checkbox"><span id="msg">Switch to Dark</span> <div id="demo">Welcome to Tutorialspoint</div> <script> document.getElementById("my_checkbox").addEventListener("click", ()=>{ let status = document.getElementById("my_checkbox"); let my_box = document.getElementById('demo'); if(status.checked == true){ my_box.style.backgroundColor = "black"; my_box.style.color = "white"; document.getElementById('msg').innerHTML = "Switch to Light"; } else{ my_box.style.backgroundColor = "white"; my_box.style.color = "black"; document.getElementById('msg').innerHTML = "Switch to Dark"; } }); </script> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
value | Yes | Yes | Yes | Yes | Yes |