
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML checked Attribute
The checked attribute of the <input> element specifies that the input type checkbox is checked when the web page loads. You can also use this attribute with input type radio.
Following is the syntax −
<input type=”checkbox” checked>
Above, we have set it checked since we wanted the checkbox to be selected when the web page loads.
Let us now see an example to implement the checked attribute of the <input> element −
Example
<!DOCTYPE html> <html> <body> <h2>Register</h2> <form action = "" method = "get"> Id: <input type = "text" name = "id" placeholder = "Enter UserId here..." size = "25"><br> Password: <input type = "password" name = "pwd" placeholder = "Enter password here..."><br> DOB: <input type = "date" name = "dob" placeholder = "Enter date of birth here..."><br> Telephone: <input type = "tel" name = "tel" placeholder = "Enter mobile number here..."><br> Email: <input type = "email" name = "email" placeholder = "Enter email here..." size = "35"><br><br> <input type = "checkbox" name = "vehicle" value = "Bike" checked>Newsletter Subscription: <br> <button type = "submit" value = "Submit">Submit</button> </form> </body> </html>
Output
In the above example, we have a form with a button −
<form action = "" method = "get"> Id: <input type = "text" name = "id" placeholder = "Enter UserId here..." size = "25"><br> Password: <input type = "password" name = "pwd" placeholder = "Enter password here..."><br> DOB: <input type = "date" name = "dob" placeholder = "Enter date of birth here..."><br> Telephone: <input type = "tel" name = "tel" placeholder = "Enter mobile number here..."><br> Email: <input type = "email" name = "email" placeholder = "Enter email here..." size = "35"><br><br> <input type = "checkbox" name = "vehicle" value = "Bike" checked>Newsletter Subscription: <br> <button type = "submit" value = "Submit">Submit</button> </form>
With that, we have also set a checkbox −
<input type="checkbox" name="vehicle" value="Bike" checked>Newsletter Subscription:
As you can see above, we have set the checked attribute, so that the input type checkbox remains checked when the page loads.
- Related Articles
- HTML checked Attribute
- HTML DOM Input Checkbox checked Property
- HTML DOM Input Radio checked Property
- HTML input readonly Attribute
- HTML input value Attribute
- How to use different step attribute in one range input in HTML?
- How to add a regular expression that an input element's value is checked against in HTML?
- HTML pattern Attribute
- HTML novalidate Attribute
- HTML maxlength Attribute
- HTML wrap Attribute
- HTML disabled Attribute
- HTML for Attribute
- HTML min Attribute
- HTML disabled Attribute

Advertisements