HTML checked attribute

HTML checked attribute: This attribute describes whether an element should be checked when the page loads. And the HTML checked attribute is of the Boolean attribute.

HTML Checked attribute

The HTML checked attribute using the element called <input> where the type is either “checkbox” or “radio”.  If you want the checked attribute also set after the page loads, with a javascript.

Syntax: <input type = “checkbox|radio” checked>



Supported Browsers

The HTML checked attribute supports different types of browsers. They are as follows:

  • Chrome 1.0
  • Mozilla 1.0
  • Internet Explorer 2.0
  • Safari 1.0
  • Opera 1.0

Example: for a checkbox

<!DOCTYPE html> 
<html> 
        <head> 
          <title>HTML checked Attribute</title> 
        </head> 
   <body style = "text-align: center;"> 
      <h1 style = "color: green;">Freshersnow</h1> 
      <h2>HTML checked Attribute</h2> 
 <form > 
        <!-- Below input elements have attribute "checked" -->
        <input type="checkbox" name="check" value="1" checked>Checked by default<br> 
        <input type="checkbox" name="check" value="2">Not checked by default<br> 
  </form> 
  </body> 
</html>					 

Output:

HTML checked attribute

Example: for radio buttons

<!DOCTYPE html> 
<html> 
       <head>  
            <title>HTML checked Attribute</title> 
        </head> 
      <body style = "text-align: center;"> 
             <h1 style = "color: green;">Freshersnow</h1> 
            <h2>HTML checked Attribute</h2> 
      <form > 
            <!-- Below input elements have attribute "checked" -->
           <input type="radio" name="check" value="1" checked>Selected by default<br> 
           <input type="radio" name="check" value="2">Not selected by default<br> 
      </form> 
       </body> 
</html>					 

Output:

HTML checked attribute for radio button