Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    CSS id Selector

    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.

    Syntax:

    #id_name{
    /* declarations */
    }

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

    CSS Id Selector Example

    Example:

    <!DOCTYPE html>
    <html>
    
        <head>
            <style>
                #mainframe {margin: auto, max-width: 1200px} 
            </style>
        </head>
    
        <body>
            <!-- 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>
            </div>
        </body>
    
    </html>


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

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.