Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

HTML checked Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The HTML checked attribute is a boolean attribute used primarily with input elements of type checkbox and radio. When applied, it specifies that an element should be pre-selected (checked) when the page loads for the first time. This attribute is useful in forms where certain options are recommended or commonly selected by users, allowing web developers to guide user choices or reflect a default state that matches the application's logic or user preferences.

For a checkbox input, the checked attribute indicates that the checkbox is ticked. For a radio button, it denotes the option that is selected by default out of a group of radio inputs sharing the same name attribute. It's important to note that for radio buttons, only one option in a given group can be checked at a time.

The presence of the checked attribute on an element represents the true state, meaning the element is checked, and its absence represents the false state. Since it's a boolean attribute, its mere presence, regardless of its value, implies a true value. Therefore, writing <input type="checkbox" checked> is equivalent to <input type="checkbox" checked="checked">.

This attribute enhances user experience by pre-defining selections that might align with the most common choices, saving users time and simplifying forms. It's also useful for settings pages where the current configuration can be reflected accurately in the form's initial state, showing checkboxes or radio buttons in their appropriate checked or unchecked states based on the user's previous selections or default settings.

Syntax

<input checked> OR <input checked="checked">

Values

  • checkedUse 'checked' (without value) or checked='checked'. Both are valid.

Applies To

Example

<form>
<input type="checkbox" id="agree" name="agreement" checked>
<label for="agree">I agree to the terms and conditions.</label>
</form>

Browser Support

The following information will show you the current browser support for the HTML checked attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 28th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!