<span> Tag in HTML

Quick facts

CategoryFlow content, phrasing content, palpable content
Content modelPhrasing content — text and other inline elements
Tag omissionNeither the start nor end tag can be omitted
Permitted parentsAny element that accepts phrasing content
DOM interfaceHTMLSpanElement

Syntax

<span class="value">content</span>

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

AttributeDescription
—<span> has no attributes of its own — only the global attributes shared by every HTML element (id, class, style, title, data-*, etc.).

Common examples

Color or style part of a sentence

Wrap just the words you want to change. The rest of the paragraph is unaffected.

<p>Our sale ends <span class="highlight">tonight</span>!</p> <style> .highlight { color: #e63946; font-weight: bold; } </style>

Update a number with JavaScript

Give a span an id and change its text from a script — handy for counters, prices and live totals.

<p>Items in cart: <span id="count">0</span></p> <script> document.getElementById("count").textContent = 3; </script>

Create a small badge or label

Spans are perfect for inline labels such as “New” or “Sale” next to a heading or product name.

<h3>Wireless Mouse <span class="badge">New</span></h3> <style> .badge { background: #7b61ff; color: #fff; font-size: 0.7em; padding: 2px 8px; border-radius: 999px; } </style>

<span> vs <div>

A <span> and a <div> are both meaningless containers, but they behave differently in the layout. A span stays inside the current line of text, while a div breaks onto its own line and takes the full width.

That makes the span the right choice for small, inline changes — coloring a word, wrapping a price or a counter — and the div the right choice for blocks of content. You can change either with CSS display, but starting with the right element keeps your HTML valid and your CSS simpler.

<span><div>
DisplayInlineBlock
Width & heightIgnored unless display changesWork as expected
Best forA few words or an iconSections and layout

Common mistakes to avoid

  • Expecting width and height to work. A span is inline, so it ignores width, height and top/bottom margins. Set display: inline-block (or block) first.
  • Using a span for meaning. If text is important or emphasised, use <strong> or <em>; a span tells screen readers nothing.
  • Putting block elements inside a span. A <div> or <p> inside a span is invalid HTML; use a div as the wrapper instead.
  • Making a span clickable. Like a div, a clickable span can’t be reached by keyboard. Use a <button> or a link.

Accessibility & SEO tips

  • For icon-only spans (such as an emoji or icon font), add aria-hidden="true" and provide the meaning as real text, so screen readers don’t read out a confusing symbol.
  • A common accessibility pattern is a “visually hidden” span: text that is hidden on screen with CSS but still read by screen readers, e.g. “(opens in a new tab)”.
  • Search engines ignore spans themselves and read the text inside, so they have no SEO effect either way.
  • Keep class names descriptive (class="price" rather than class="red") so your spans still make sense when the design changes.

Browser support

Supported in every browser, including Chrome, Edge, Firefox, Safari and their mobile versions — it has been part of HTML since the very first versions.

Related tags

Frequently asked questions

Does <span> add a line break?
No — it's an inline element, so it flows with the surrounding text instead of starting on a new line the way a <div> or <p> would.
What's a common use for <span>?
Styling or scripting part of a sentence — for example, coloring a single word, wrapping a value you plan to update with JavaScript, or adding a tooltip to one phrase.
How do I give a <span> a width?
Set display: inline-block on the span. It stays in the line of text but now accepts width, height, padding and margins in every direction.
Can a <span> contain a <div>?
No. A span may only contain inline content such as text, links, images and other spans. Swap the outer span for a div if you need to wrap block content.
Does <span> affect SEO?
No. Search engines read the text inside a span normally but give the element itself no meaning. Use headings and semantic tags when you want to signal importance.
Should I use <span> or <strong> to make text bold?
Use <strong> when the text is genuinely important, because that meaning reaches screen readers and search engines. Use a <span> with CSS font-weight: bold when the bold is only a visual design choice, such as a styled price.