HTML Tutorial

HTML Tag: <span>

Usage of <span>

The HTML <span> tag is an inline element used to group or style a portion of text. It does not affect the document's structure but provides additional semantic or visual cues.

Attributes of <span>

  • id: Unique identifier for the <span> element.
  • class: CSS class name(s) to apply styling.
  • title: Tooltip or descriptive text for screen readers.
  • style: Inline CSS styles.

Examples with <span>

  • Highlight text: <span style="color: red;">This text is highlighted.</span>
  • Add spacing: <span style="margin: 5px;">This text has extra spacing.</span>
  • Change cursor: <span style="cursor: pointer;">This text changes the cursor to a pointer.</span>

Exploring the <span> Tag

<p>
  This is a paragraph of text.
  <span style="color: green;">This is a green span.</span>
</p>

Output:

This is a paragraph of text. This is a green span.

In this example, the <span> tag is used to add green color to a portion of the text within the paragraph, highlighting it visually.