Note:
id
attribute can be used with any HTML element.id
value is case sensitive.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.
Hanoi is the capital of Vietnam.
Paris is the capital of France.
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
Then add the path to this bookmark ('Go to Chapter 4), from the same page.
Đi tới Chương 4
Or add a link to this bookmark from another page.
Đi tới Chương 4
Previous article: Class properties in HTML
The following article: Iframe in HTML