1. Home
  2. Computing & Technology
  3. Web Design / HTML

The SPAN Tag

By Jennifer Kyrnin, About.com

Description of the SPAN Tag:

The <span> tag in XHTML is a tag that groupings of inline content (defined) within the content of a page. What this means is that a <span> tag defines portions of Web elements to make them easier to manage, style, and manipulate. You can use the <span> tag when you want to change the color of a single word. The <span> tag is a very powerful tool for Web developers because it is so open-ended. The span tag can do anything you want it to do.

HTML Definition of the SPAN Tag:

In order to use the <span> tag you need to know the HTML definition of the <span> tag. Some key tips:

  • The <span> tag is an inline-level element.
  • The <span> tag can only contain other inline elements like abbr, strong, or tt.
  • The <span> tag can be inside <p> tags or <div> tags.

Tips for Using the SPAN Tag:

  • The <span> tag doesn't do anything by itself. In fact, the only attribute that might affect the page is the title attribute, and that depends upon the Web browser.
  • Use span tags when you don't want any changes to the layout other than exactly what you specify in the styles of the span. For example, if you use a <div> or <p> most browsers will add space around the element, because they are block elements.
  • It's always a good idea to close your <span> tags as soon as you open them. Then place the contents within the element.
  • If you nest your <span> tags, be sure that you know where your content is going (in other words, which SPAN it should be part of).

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. HTML Tags
  7. The SPAN Tag

©2008 About.com, a part of The New York Times Company.

All rights reserved.