<span>

The HTML <span> element serves as a generic inline container for grouping and styling portions of text or other inline elements, without imparting any semantic significance or altering the document structure.

<span> Tag

The <span> tag in HTML is an inline container used to group elements or apply styles without introducing a new block-level structure. It does not modify content presentation on its own but allows CSS styling or JavaScript functionality to be applied to specific text or inline elements.

Syntax

index.html
<span>Text or elements to style</span>

<span> Demo

{idx=1}
The element

My mother has red eyes, and my father has dark green eyes.

index.html
<h1>The <span> element</h1>
<p>My mother has <span>blue</span> eyes, and my father has <span>dark green</span> eyes.</p>

Attributes

Definition and Usage

  • The <span> tag serves as an inline container to style or emphasize portions of text or content within a document.
  • It can be styled with CSS or manipulated using JavaScript by applying class or id attributes.
  • Unlike the <div> element, which is block-level, <span> remains inline.

Default CSS Settings

  • None.

See Also

HTML <div> element

Conclusion

The <span> tag is a versatile inline container that allows developers to style or manipulate specific portions of text or inline elements without affecting the document's layout. It is commonly used for applying CSS styles or JavaScript functionality to targeted content. Unlike block-level elements, <span> does not introduce line breaks, making it perfect for inline styling.