HTML Id
The HTML id attribute is used to specify a unique id for an HTML element.
Using The id Attribute
You cannot have more than one element with the same id in an HTML document. The `id` attribute is often used to point to a specific style declaration in a style sheet. It is also used by a JavaScript to access and manipulate the element with the specific id.
The syntax for id is: write a hash character (#), followed by an id name. Then, define the CSS properties within curly braces {}.
ID Attribute Example
Result
The id name is case sensitive! The id name must contain at least one character, and must not contain whitespaces (spaces, tabs, etc.).
Difference Between Class and ID
A class name can be used by multiple HTML elements, while an id name must only be used by one HTML element within the page:
Class vs ID Example
Result