CSS id Selector

CSS id selector selects an element that has the specified id attribute. As an id is always unique within a page, therefore, the id selector always selects a single element from the page and applies CSS styles to it.

To select an element using the id selector, use a hash symbol(#) followed by the id of the element. For example, #myId.

In the example below, the id selector selects a <p> element that has id="p2" and applies CSS styles to it. Try it out to see how it works:

Example:

#p2{
  background: yellow;
  border: 2px dashed blue;
  padding: 10px;
}

CSS id Selector Syntax

#id{
    CSS styles
}

Related Pages

CSS Tutorial: CSS Selectors

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.