Cơ BảnHTML iconHTML

Custom attribute (data-*) là gì?

Cho phép lưu trữ dữ liệu tùy chỉnh trên HTML element mà không vi phạm HTML spec.

  • Cú pháp: data-user-id="123".
  • Truy cập qua JS bằng element.dataset.userId (tự convert kebab-case sang camelCase). Ứng dụng: truyền data từ HTML sang JS, CSS selectors ([data-active]), testing (data-testid).
  • React dùng data attributes để pass info cho DOM.

Xem toàn bộ HTML cùng filter theo level & chủ đề con.

Mở danh sách HTML