CSS ID Selector
Description
The id selector is one of the most specific and powerful selectors in CSS, used to target a single element on a page that has a unique id attribute. Unlike class selectors, which can apply to multiple elements, an id must be unique within the HTML document, making it ideal for styling or manipulating a specific element directly. Using the id selector allows developers to apply precise styling, such as changing colors, dimensions, or layout, to one element without affecting others.
When using the id selector, it is common to pair it with various class selectors or element selectors to increase specificity or create more complex styling rules. For example, you might use an id selector to style a specific header on a page while other headers remain unaffected. This makes it especially useful for unique components like navigation bars, hero sections, or modal dialogs.
The id selector is frequently combined with CSS properties like color, background-color, or display to modify an element’s appearance. For instance, if you have a page section with id="hero", you could write:
#hero {
background-color: #f0f0f0;
padding: 2rem;
text-align: center;
}
In this example, only the element with id="hero" will receive the specified background, padding, and alignment, leaving all other elements untouched.
The specificity of the id selector also makes it useful in overriding styles from less specific selectors. For example, even if a class applies a certain style to many elements, a rule using the id selector for a particular element will take precedence. This property of specificity makes id selectors powerful but should be used thoughtfully to avoid overly rigid CSS that is difficult to maintain.
Syntax
#id { css declarations; }
Example
Browser Support
The following information will show you the current browser support for the CSS ID selector. Hover over a browser icon to see the version that first introduced support for this selector.
This CSS id selector is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 2nd January 2026
