span ElementThe span element is an inline element declared by the XHTML 1.1 Text Module (Inline Structural)
Elements in the Text Module are:span | br (Inline Structural Support Module)em | strong | q | cite | abbr | acronym | code | var | kbd | samp | dfn (Inline Phrasal Support Module)div | p (Block Structural Support Module)h1 - h6 | blockquote | pre | address (Block Phrasal Support Module)
The span element is used as a general inline container, where content can be
grouped without there being any intrinsic significance to the tag. Attributes of the span element
can be used to assign a class or
id (for reference within a style sheet or script) or to add a
title. Another useful attribute is
xml:lang, which allows a particular language to be
associated with the content of the span.
For example: if, for stylistic reasons you wanted the name of your business to appear
in dark red, bold-faced text throughout your site, you could enclose each occurrence of the
name within a span element with a class
attribute of, say, "us" and then use the CSS style rule:
span.us { font-weight:bold; color:#900 } to achieve the desired effect. Like so:
<p>Here at <span class="us">Hippopotamus Enterprises</span>,
we have a fun and relaxed, yet conscientious attitude to our work,
which is why we know you'll find that <span class="us">Hippopotamus Enterprises</span>
organise the best corporate parties in the world.</p>
With the style rule above, this example renders as:
Here at Hippopotamus Enterprises, we have a fun and relaxed, yet conscientious attitude to our work, which is why we know you'll find that Hippopotamus Enterprises organise the best corporate parties in the world.
The content of a span needn't be just text - other inline elements may be enclosed, such as a,
img, em and so on - see the
Content Model for span.
See also the div element, which is the block level equivalent of span.
There are no #REQUIRED attributes on the span element.
There are no specific attributes declared on the span element.
span element are listed below:class [ type NMTOKENS ]id [ type ID ]style [ type CDATA ], from the Style Attribute Module (deprecated)title [ type Text ]xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Modulexml:lang [ type LanguageCode ]All attributes in the
Events Attribute Collection
are supported:onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
span element is:
( #PCDATA | Inline.mix )*
See Content Model & Nesting for information about Content Model syntax and Nesting Groups.
spanabbr, acronym, br, cite, code, dfn, em, kbd, q, samp, span, strong, varabutton, input, label, select, textareaimgb, big, i, small, sub, sup, ttmapnoscript, scriptdel, insbdoobjectrubyspanabbr, acronym, address, cite, code, dfn, div, em, h1 - h6, kbd, p, pre, q, samp, span, strong, varadd, dt, licaption, td, thbutton, fieldset, label, legendb, big, i, small, sub, sup, ttdel, insbdoobjectrb, rt