Checkbox marked by default

Checkboxes are elements HTML that allow us to capture, from the user, multiple selections on a topic. They are usually very used when we are surveying the user about their preferences. In such situations, there may be a case of giving you selections marked by default. That is why we will have to know how to mark the default checkboxes.

But let’s go by steps. The first thing we have to remember is that checkboxes are input of type checkbox. To include a checkbox we must use the following line of code:

      
      

We see that in addition, we use the label to provide content to the checkbox. Since otherwise only the selection box would appear without any text.

In this way a set of checkboxes would look like this:

      
      
      
      
      
      

If now we want one of the checkboxes to appear checked by default, we must use the attribute checked of the input.

      
      

With the previous code the football check would appear marked.

The complete code would be as follows:

      
      
      
      
      
      

Leave a Comment