iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML Global Attributes

Global attributes can be used on (almost) any HTML element. Memorise these — they cover most of what you actually type.

Identification & styling

AttributePurpose
idUnique identifier on the page.
classOne or more space-separated class names.
styleInline CSS for this element only.
titleTooltip text on hover.
data-*Custom data attributes — read via element.dataset.

Language & direction

AttributePurpose
langLanguage of the element's content (e.g. en, fr).
dirText direction: ltr, rtl, or auto.
translateyes or no — tells translation tools to skip.

Interaction

AttributePurpose
tabindexOverride tab order. 0 = focusable; -1 = focusable only by script.
contenteditabletrue makes any element editable in place.
draggabletrue enables drag-and-drop.
hiddenHide the element from rendering.
spellchecktrue / false for editable text.
autofocusFocus on page load (use sparingly).

Accessibility

AttributePurpose
roleARIA role (use only if the semantic element doesn't fit).
aria-labelAccessible name when there's no visible label.
aria-labelledbyReference another element's id as the label.
aria-hiddenHide from assistive tech.

Example

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML Global Attributes</title>
</head>
<body>

<h1>HTML Global Attributes</h1>
<p>This is a demo page for the "HTML Global Attributes" lesson.</p>

</body>
</html>
Try it Yourself »

Exercise

Mark this section as the page in Spanish using the global lang attribute.

<section ="es">¡Hola!</section>

Test yourself

Q1. class, id, style, title are…
Q2. data-* attributes are read in JS via…
Q3. aria-* attributes provide…

Discussion

Loading…