Global Attributes and Metadata Attributes
Some attributes can be used on almost any element. These are called global attributes. They help with styling, scripting, accessibility, language, editing, and browser behavior.
Common Global Attributes
id
Purpose:
- gives one unique identifier to an element
Example:
<section id="about"></section>
class
Purpose:
- groups elements for CSS or JavaScript
Example:
<p class="intro highlighted">Welcome!</p>
title
Purpose:
- provides advisory text, often shown as a tooltip
lang
Purpose:
- describes the language of the content
Possible values:
enen-USesfr
hidden
Purpose:
- hides content from normal rendering
tabindex
Purpose:
- controls keyboard focus order
Common values:
0-1
contenteditable
Purpose:
- allows users to edit the element's content
Possible values:
truefalse
draggable
Purpose:
- marks whether an element can be dragged
Possible values:
truefalseauto
dir
Purpose:
- sets text direction
Possible values:
ltrrtlauto
Metadata Attributes in the Head
Important attributes commonly used on <meta> and <link> include:
charsetnamecontenthttp-equivrelhrefmediasizes
Example:
<meta name="description" content="A beginner HTML5 course">
<link rel="icon" href="favicon.ico">
Why Global Attributes Matter
They are the glue between HTML structure and:
- CSS styling
- JavaScript behavior
- accessibility support
- localization
- SEO