CSS ID Selector

An ID can only be used once per page, and is a unique identifier to an element. Typically, an ID is used for any unique page element such as the header, main navigation, footer, or other key part of the user interface.

The most common way to apply an ID is to reference it in the (X)HTML using the id="name" attribute immediately after the opening tag within an element. In this case, our two IDs are named highlight and default, respectively, and are applied to two paragraphs:


This paragraph has red text.

This paragraph has dark gray text.

The corresponding CSS uses the hash (#) character to denote the rule is a unique ID. The hash is combined with the ID name to start the rule.