id phải duy nhất trên toàn trang, chỉ gán cho 1 element duy nhất — dùng cho anchor links (#section) và getElementById(). class dùng lại được, nhiều element chia sẻ cùng class, 1 element có thể có nhiều class.
- CSS specificity: id (0,1,0,0) cao hơn class (0,0,1,0), nên tránh dùng id để style vì khó override.
- Trong React, dùng
htmlForthayforvàclassNamethayclass.
id must be unique across the entire page, assigned to only one element — used for anchor links (#section) and getElementById(). class is reusable; multiple elements can share a class, and one element can have multiple classes.
- CSS specificity: id (0,1,0,0) is higher than class (0,0,1,0), so avoid using id for styling as it's hard to override.
- In React, use
htmlForinstead offorandclassNameinstead ofclass.