The checked attribute is a small instruction attached to an HTML element. Its job is to preselect a checkbox or radio control. It is easier to remember when you can see it in a real piece of markup.
What checked is used for
Preselect a checkbox or radio control. The attribute appears inside an element’s opening tag. Depending on its definition, it may take a specific string, a number, an enumerated keyword, or be a boolean attribute.
The example below uses it in a checkbox context. Other elements may support it too, or may give the same attribute a different meaning.
Example you can try
<form action="/save" method="post">
<label for="example-field">Example checked</label>
<input id="example-field" name="example_field" type="checkbox" checked>
<button type="submit">Save</button>
</form>
How the example works
Look for checked in the snippet. Here the example shows its presence without a string value. This is a concrete input the browser can interpret; it is not just text shown to the reader.
Checked is a boolean attribute: checked="false" still means checked in HTML markup.
Values and important behavior
Use the value format shown by the HTML definition. Do not assume that a value accepted in one attribute also works in another. When a browser ignores an invalid value, inspect the element and correct the markup.
This detail matters most when the page receives user input, navigates to another document, or loads an external resource. In those cases, check the browser behavior and any server-side requirements separately.
Small practice task
Copy the code and change checked to another sensible value, or remove it entirely if it is optional. Test the difference in the browser and inspect any submitted value or network request.
Common Beginner Mistakes
- Checked is a boolean attribute: checked="false" still means checked in HTML markup.
- Using
checkedon an element that does not support it. - Believing that an HTML hint or client-side check replaces real server validation or a security policy.
Key Takeaways
checkedis used to preselect a checkbox or radio control.- Checked is a boolean attribute: checked="false" still means checked in HTML markup.
- Choose valid values and test the result instead of guessing what the browser will do.