Skip to main content

The <span> Element

As defined in the HTML Living Standard, the <span> element doesn't mean anything on its own, but can be useful when used together with the global attributes, such as class, lang, or dir. It represents its children.

Visual Example:

The span element is an inline container with no inherent semantic value.

<p>This is a <span class="highlight">word</span> in a sentence.</p> View HTML Living Standard: The span element

The "Last Resort" Rule

Much like the <div> element is a generic block container, the <span> is a generic inline container.

WCAG Requirement: Info and Relationships

Success Criterion 1.3.1 (Level A): Information, structure, and relationships conveyed through presentation can be programmatically determined.

A common accessibility failure is using <span> to simulate semantic elements. For example, styling a span to look like a heading (large, bold) or a button (boxed, interactive) without providing the equivalent programmatic info. If you must use a span for a functional role, you must use ARIA roles and states (e.g., role="button").

Understand SC 1.3.1: Info and Relationships

Effective Usage with Attributes

While <span> has no meaning, it is the perfect vehicle for global attributes that do carry meaning:

<p> The French call it <span lang="fr">joie de vivre</span>. </p>

A11y Tip: Screen Reader Only Text

A common accessibility module is the "SR-Only" class. This uses a <span> to provide extra text that is hidden from sighted users but announced by screen readers to provide context that is otherwise conveyed only visually.

<button> <span aria-hidden="true">+</span> <span class="sr-only">Add to cart</span> </button>