Cyber Code Academy
Tutorials Academy Courses
Home / html-tutorials-md / HTML Data Attributes

HTML Data Attributes

> Store custom, non-sensitive information using data-* attributes.

**Category:** HTML | **Lesson:** 25 of 40

## Example
“`html

HTML Fundamentals

“`

## Read with JavaScript
“`html

const card = document.querySelector(“.course-card”);
console.log(card.dataset.courseId);
console.log(card.dataset.level);

“`
data-course-id becomes dataset.courseId.

## Best practices
Use data attributes for custom data relevant to the element. Do not replace semantic HTML with data attributes or put private information in them.

## Practice
Create three course cards with different data-course-id and data-level values and read them with JavaScript.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses