CSS - Id Selector




CSS Id Selector

The id selector uses the id attribute of an HTML tag to find the specific element.

An id should be unique within a page, so you should use the id selector when you want to find a single, unique element.

To find an element with a specific id, write a hash character, followed by the id of the element.

The style rule below will be applied to the HTML element with id="p1":

Syntax

#id {
    css declarations;
}

Example

<html>
     <head>
        <style type="text/css">
        #paragraph{
        font-size:35px;
        background-color:#0000FF;
        color:#00FFFF;
        padding:5px;
        }
        </style>
        </head>
        <body>
        <p id="paragraph">Welcome to CSS Tutorial</p>
     </body>
    </html>

Result