Welcome to our detailed guide on HTML checkboxes, a crucial aspect of web development that allows users to make selections from a list of options. Today, we're focusing on checkboxes that are checked by default, enhancing user experience by pre-selecting relevant options.

Checkboxes are HTML elements defined by the <input> tag with type "checkbox". To create a checked checkbox, we use the checked attribute. Let's dive in to learn how to do this and explore some useful applications.

Creating a Checkbox that Starts as Checked
To create an HTML checkbox that is checked by default, include the checked attribute in the <input> tag.

Here's an example:
<input type="checkbox" checked> Pre-selected
Using the checked Attribute

The checked attribute enables the checkbox to be checked from the moment the web page loads. It's a straightforward way to pre-select an option, improving UX when user choices align with common or likely options.
Example:
<input type="checkbox" checked> I agree to the Terms and Conditions
Unchecking a Checked Box

To uncheck a box that starts as checked, remove the checked attribute. This returns the checkbox to its unchecked state, awaiting user interaction.
Example:
<input type="checkbox"> Deselected by default
Manipulating Checked Boxes with JavaScript

JavaScript enhances the interactivity of checked boxes, allowing you to change their state dynamically based on user actions or other conditions.
To check a box using JavaScript, set the checked property to true. Conversely, setting it to false unchecks the box.




















Checking a Box with JavaScript
Here's an example of checking a box using JavaScript:
<input type="checkbox" id="myCheckBox">
Unchecking a Box with JavaScript
Unchecking a box involves setting the checked property to false. Let's see how to do it:
<input type="checkbox" id="myCheckBox" checked>
From pre-selecting options to dynamically controlling checkbox states, this approach streamlines user interactions and enhances the overall webpage experience. Now go and add interactivity to your forms with checkboxes that are checked by default!