Skip to content

<span> - The Generic Inline Container

Inline HTML 3.2

The span element is a generic inline container for phrasing content. It has no semantic meaning on its own and is used for styling purposes or as a hook for JavaScript.

Result
<span>inline content</span>

The <span> element is purely a container with no inherent meaning.

Use <span> when you need to:

  • Apply CSS styling to part of inline content
  • Target specific text with JavaScript
  • Group inline elements for manipulation
  • No appropriate semantic element exists
Result
Result
Result
Result
Result
Result
<!-- Don't use span for emphasis -->
<p>This is <span class="important">very important</span>.</p>
<!-- Don't use span for code -->
<p>Use the <span class="code">console.log()</span> function.</p>
Instead of <span>Use
Emphasized text<em> or <strong>
Code snippets<code>
Keyboard input<kbd>
Sample output<samp>
Variables<var>
Abbreviations<abbr>
Citations<cite>
Definitions<dfn>
Time/dates<time>
Quotations<q>
Result
Result
Result
Result
Result
Result

Remember that <span> has no semantic meaning for screen readers. Add ARIA attributes when necessary:

<!-- Add role and label when needed -->
<span role="status" aria-live="polite" id="status">
Loading...
</span>
<p>Error: <span style="color: red;">Invalid input</span></p>
<span>Heading</span>
<span>This is a paragraph</span>
<!-- Inline container -->
<p>This is <span class="highlight">inline</span> content.</p>

Doesn’t break line flow.

BrowserVersionNotes
Chrome1+Full support
Firefox1+Full support
Safari1+Full support
Edge12+Full support
IE3+Full support

The <span> element has been supported since the earliest browsers.