Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Inline Text

The <span> element

Reference for the HTML <span> element: a meaning-free inline container for styling, scripting and language changes, when to choose it and technical details.

The <span> element is a generic inline container. It has no meaning and no default styling: it simply groups a run of text or inline elements so you can target it with CSS or JavaScript, or attach attributes such as lang, dir or title to just that part of a sentence. It is the inline counterpart of <div>.

HTML
<p>Status: <span class="badge">Shipped</span></p>

Try it

Generic inline hooks

The three paragraphs show the main jobs of <span>: a styling hook, a way to set lang on a phrase, and a target for a script.

Attributes

This element has no attributes of its own. It accepts the global attributes; class, id, lang, dir, title and data-* are the ones you will use most.

Usage notes

  • Last resort. Reach for <span> only when no element with real meaning fits. Important text is <strong>, stressed text is <em>, a date is <time>, code is <code>, and so on.
  • Not interactive. A clickable <span> is not focusable and is not announced as a control. Use <button> or <a> instead of adding click handlers to a span.
  • Language changes. Wrapping a foreign phrase in <span lang="โ€ฆ"> helps screen readers pronounce it and lets browsers choose correct hyphenation and quotation marks.
  • Phrasing content only. A span may only contain inline (phrasing) content. Putting a <div> or <p> inside it is invalid, even if you change its CSS display.
  • Accessibility. A span is ignored by assistive technology, apart from its text. Adding an ARIA role can change that, but a native element is almost always the better choice.

Technical summary

Content categories Flow content, phrasing content, palpable content
Permitted content Phrasing content
Tag omission None; both the start and end tags are required
Permitted parents Any element that accepts phrasing content
Implicit ARIA role generic
DOM interface HTMLSpanElement
Default display inline

Browser support

Supported in every browser.