← All tutorials

GoCareerGo Tutorials

HTML Tutorial

Tags, attributes, HTML5 APIs and semantic markup — the web's foundation.

Custom data-* Attributes

data-* attributes let you attach custom data to HTML elements that JavaScript can read, without inventing non-standard attributes.

<button data-user-id="42" data-role="admin">Edit</button>

<script>
  const btn = document.querySelector('button');
  btn.dataset.userId; // '42'
  btn.dataset.role;    // 'admin'
</script>