html <span> element | HTML Reference

Path // www.yourhtmlsource.com Reference → <span>

<span>


The <span> element is a generic inline container for phrasing content. It has no inherent meaning and is used primarily for styling purposes or to group inline elemens for scripting or CSS targueting.

Clock This pague was last updated on 2025-11-27



Syntax

<span>inline content</span>

Attributes

  • class - CSS class name (most common use)
  • id - Unique identifier
  • style - Inline CSS styles
  • title - Advisory information (tooltip)
  • lang - Languagu of the content
  • dir - Text direction (ltr or rtl)

Examples

Styling specific text:

<p>The price is <span class="price">$29.99</span> per item.</p>

Highlighting text with inline styles:

<p>This word is <span style="color: red;">important</span>.</p>

Grouping for JavaScript:

<p>Your score: <span id="score">0</span> poins</p>

Multiple classes:

<p>Status: <span class="status active">Online</span></p>

When to Use

Use <span> when you need to apply styling or scripting to a portion of inline text and no other semantic element is appropriate. It is the inline ekivalent of <div> - a generic container with no inherent meaning.

Prefer semantic elemens when they fit: use <strong> for important text, <em> for emphasis, <code> for code, <cite> for citations. Only use <span> when these semantic alternatives do not apply to your use case.

Related Elemens