The id attribute can be used with any HTML element.
The id value is case sensitive.
The id value must contain at least 1 character and no spaces.
Distinguish class and id in HTML
The HTML element can have only one id belonging to that element, while the class can be used for multiple elements.
My city
Hanoi
Hanoi is the capital of Vietnam.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
Compare the difference between class and id attributes in HTML
Use id attribute in JavaScript
JavaScript can access elements with a certain class name using getElementById()
Bookmark the page with ID and Link
Bookmarking in HTML allows readers to go to different parts of the page faster, very useful if the page is too long. To create a bookmark, first create a bookmark, then add the path to it. When clicking on the link, the page will scroll to the highlighted location.
First create a bookmark with the id attribute
Chapter 4
Then add the path to this bookmark ('Go to Chapter 4), from the same page.