HTML - attributes - checked

revision:


Content

"checked" attribute: a boolean attribute that pre-selects an element syntax some examples


"checked" attribute: a boolean attribute that pre-selects an element

top

When present, it specifies that an <input> element should be pre-selected (checked) when the page loads.
The checked attribute can be used with <input type="checkbox"> and <input type="radio">.
The checked attribute can also be set after the page load, with a JavaScript.


syntax

top

<input type = "checkbox | radio" checked />

<input type = "checkbox | radio" checked="checked" />

The checked attribute indicates that the input element is checked, i.e. selected. Clicking the element will toggle, i.e. check or uncheck, the item.


some examples

top




codes:
                    <form style="margin-left:5vw;" ction="/action_page.php" method="get">
                        <input type="checkbox" name="vehicle1" value="Bike">
                        <label for="vehicle1"> I have a bike</label><br>
                        <input type="checkbox" name="vehicle2" value="Car">
                        <label for="vehicle2"> I have a car</label><br>
                        <input type="checkbox" name="vehicle3" value="Boat" checked>
                        <label for="vehicle3"> I have a boat</label><br><br>
                        <input type="submit" value="Submit">
                    </form>
                



codes:

                    <form style="margin-left:5vw;" action="#">
                        <label>Status</label><br />
                        <input type="radio" id="pending" name="status" value="Pending" checked>
                        <label for="pending">Pending</label><br />
                        <input type="radio" id="closed" name="status" value="Closed">
                        <label for="closed">Closed</label><br />
                        <input type="submit" value="Submit">