HTML <span>
Anonymous contributor
Published Jul 1, 2022Updated Apr 4, 2023
Contribute to Docs
The <span> element is used for grouping text or elements together for styling and scripting. Unlike the block-level <div> element, <span> is an inline element that is usually wrapped inside another element. (<li>, <p>, etc.)
This element should only be used whenever there is no semantic element to use instead.
Syntax
<span attributes=""><!-- Place content here. --></span>
The <span> element can be selected with attributes, such as class or style.
Example
In the example below, a familiar poem is marked up with <span> wrapped in a single <p> element:
<p>Roses are <span style="color: red;">Red</span>,<br />Violets are <span style="color: blue;">Blue</span>,<br />We think HTML is <span style="color: orange">awesome</span>!<br />What about <span style="text-decoration: underline;">you</span>?</p>

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn HTML on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
- Beginner Friendly.7 hours