demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

The span tag

<span> is the second-most commonly misunderstood tag in the HTML lexicon, after <div>. A useful way to think of <span> is this: it is an inline tag that is the liferaft of XHTML, used only after every other possible tag has been eliminated. There are almost always other, better options.

The reason <span> is employed as a last resort is that it lacks any semantic value: there’s no telling what the content wrapped by <span> represents. In addition, <span> is entirely useless without some attached CSS: applied by itself, it makes no difference at all to presentation. A combination of both factors relegates <span> to rare, considered and careful use in a site.

A typical use of <span> is within a block element, to wrap content that cannot otherwise be reached via CSS. For example:

  1. <p>In this paragraph, I want a particular word to be treated
  2. <span class=”special”>differently<span> for whatever reason.</p>

Again, we should have eliminated all other possibilities before applying <span>, rejecting inline semantic markup like <dfn> and <acronym>, <em> and <strong>, all of which can have CSS applied to them.

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.