totn HTML

HTML: <span> tag

This HTML tutorial explains how to use the HTML element called the <span> tag with syntax and examples.

Description

The HTML <span> tag defines a generic inline container in an HTML document. This tag is also commonly referred to as the <span> element.

Syntax

In HTML, the syntax for the <span> tag is:

<body>
<p><span>Span text goes here</span> and not here</p>
</body>

The <span> tag is traditionally used for style purposes, for example, to change the color of the text to red:

<body>
<p><span class="red_text">Span text goes here</span> and not here</p>
</body>

Sample Output


Attributes

Only the Global Attributes apply to the <span> tag. There are no attributes that are specific to the <span> tag.

Note

  • The HTML <span> element is found within the <body> tag.
  • The <span> tag is generally used for styling purposes when there is no other element to use.
  • The <span> tag does not inherently represent anything.

Browser Compatibility

The <span> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <span> tag below, exploring examples of how to use the <span> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.