SyntaxStudy
Sign Up
HTML Styling with CSS IDs
HTML Beginner 3 min read

Styling with CSS IDs

CSS IDs

CSS IDs target a unique element using id="name" and #name. IDs must be unique per page.

IDs have very high specificity, making them harder to override with other selectors.

Example
<header id="site-header">
  <nav>...</nav>
</header>

/* CSS */
#site-header {
  position: sticky;
  top: 0;
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
Pro Tip

Reserve IDs for JavaScript targeting or anchor links; use classes for all visual styling.