Skip to main content
Syllabus
On this page

HTML Global Attributes Reference

Badar KhalilUpdated September 27, 2026 2 min read

HTML Global Attributes Reference

HTML global attributes are attributes that can be applied to almost any HTML element, regardless of tag type. Mastering these global attributes gives you fine control over styling, accessibility, scripting hooks, and user interaction across your entire webpage.

What Are Global Attributes?

Unlike attributes that only work on specific tags (like href on <a>), HTML global attributes work on virtually every element — from <div> to <p> to <button>. This makes them essential building blocks for CSS styling, JavaScript interactivity, and accessible web design.

1. Identification Attributes

AttributeDescription
idUnique identifier for an element, used in CSS/JS targeting
classAssigns one or more class names for styling/scripting
nameNames an element (mostly for form elements)

2. Styling Attributes

AttributeDescription
styleApplies inline CSS directly to an element
classLinks an element to CSS rules defined in a stylesheet

3. Content and Behavior Attributes

AttributeDescription
titleAdds a tooltip shown on hover
hiddenHides an element from rendering
contenteditableAllows the user to edit the element's content
draggableMarks an element as draggable
spellcheckEnables or disables spellchecking on editable content
translateIndicates if content should be translated

4. Data Attributes

AttributeDescription
data-*Custom attributes used to store extra data, accessed via JavaScript's dataset API

5. Accessibility & Language Attributes

AttributeDescription
langSpecifies the language of the element's content
dirSets text direction: ltr, rtl, or auto
tabindexControls keyboard focus order
accesskeyDefines a keyboard shortcut to focus/activate the element

6. Event Handler Attributes

Global event attributes like onclick, onmouseover, and onfocus can be attached to nearly any element to trigger JavaScript directly from HTML.

AttributeDescription
onclickRuns script when the element is clicked
onmouseoverRuns script when the mouse hovers over the element
onchangeRuns script when an element's value changes

Why Global Attributes Matter for Modern Web Development

Using HTML global attributes correctly improves accessibility (via lang, tabindex, title), enables dynamic behavior (via data-* and event attributes), and keeps your code clean and reusable through id and class.

Try It Yourself

Practice with the live code examples below to see global attributes in action.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself JAVASCRIPT
Output

Press Run to execute.

Exercise: Use Data Attributes in JavaScriptHTML

Create a div with a data-* attribute storing a product price. Write JavaScript that reads the value using the dataset API and logs it to the console.

Try it Yourself HTML
Output

Press Run to execute.

Show expected output
Console logs the price value stored in the data-price attribute.

This is a self-check — compare your result with the expected output above.

Was this page helpful?