The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

The id value can be used by CSS and JavaScript to perform certain tasks for a unique element with the specified id value.

In CSS, to select an element with a specific id, write a hash (#) character, followed by the id of the element:


Use CSS to style an element with the id “myHeader”:

#myHeader {
    background-color: lightblue;
    color: black;
    padding: 40px;
    text-align: center;

<h1 id="myHeader">My Header</h1>



Leave a Reply

Your email address will not be published. Required fields are marked *