ID Selector-Introduction to CSS [CSS3 compatible]

The ID selector is for specifying the ID of the element to which the style sheet (CSS) is applied.

The ID selector starts with "#" and specifies the ID name of the element you want to apply. The "#menu" part is the ID selector.

#menu {
  color: red;
}

Let's use the ID selector.

<style>
  #menu {
    color: red;
  }
</style>

<div id = "menu">
  Grilled meat
</div>

Should I use the ID selector or the class selector?

Basically, it is recommended to use only class selector in the stylesheet (CSS).

Identity selectors require elements to be unique, while class selectors are flexible and can be applied to multiple elements with the same class name.

Associated Information