DEV Community

QUBE
QUBE

Posted on

Class & Id in HTML

  1. In HTML, the id and class attributes are used to identify and group elements, primarily for styling with CSS and manipulating with JavaScript. The key difference is that an id must be unique within a page, while a class can be used on multiple elements

class Attribute

  • Must be unique to a single element in the HTML document.

  • Uses a hash symbol (#) (e.g., #header).

  • Higher specificity.

  • Only one id per element.

  • Can be used for anchor links (jump links) within a page

id Attribute

  • Must be unique to a single element in the HTML document.

  • Uses a hash symbol (#) (e.g., #header).

  • Higher specificity.

  • Only one id per element.

  • Can be used for anchor links (jump links) within a page

Top comments (0)