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>.
<p>Status: <span class="badge">Shipped</span></p>
Try it
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 CSSdisplay. - Accessibility. A span is ignored by assistive technology, apart from its text. Adding an ARIA
rolecan 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.
Related
<div>โ the generic block container<mark>โ highlighted text- Global attributes โ
class,id,langand more - Lesson: Div and Span
- Lesson: Block and Inline Elements
- Lesson: Classes