CSS id selector is used to select the HTML element using the ID attribute to apply a style to it. This id element is distinctive always inside the page, and hence it is preferred for selecting a distinct, unique HTML element. When you want to apply the style to only one HTML tag at a time on a page, then you can use the ID selector.

Id selector can be implemented by writing it with the hash (#) character, trailing with your desired element's id.


/* declarations */

Here is an example of an Id selector implemented on a particular div tag:

CSS Id Selector Example


<!DOCTYPE html>

            #mainframe {margin: auto, max-width: 1200px} 

        <!-- On this element, the ID selector class will be applied. -->
        <div id="mainframe">
            <!-- This is the main container of page. -->
            <p>This paragraph is not assigned with id selector and hence no affect on it.</p>


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram