NOTICE: This website is no longer updated or supported - as such many of the techniques used to build it may seem antiquated in the modern day. It is preserved for historical reasons only.

HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<span> (Text Span)


This element typically is used to group inline text so scripting or style rules can be applied to the content. As it has no preset or rendering meaning, this is the most useful inline element for associating style and script with content.

Standard Syntax


<span
class="class name(s)"
dir="ltr | rtl"
id="unique alphanumeric string"
lang="language code"
style="style information"
title="advisory text"
</span>

Attributes Defined by Internet Explorer


accesskey="key" (5.5)
contenteditable="false | true | inherit" (5.5)
datafld="column name" (4)
dataformatas="html | text" (4)
datasrc="data source id" (4)
hidefocus="true | false" (5.5)
language="javascript | jscript | vbs | vbscript" (4)
tabindex="number" (5.5)
unselectable="on | off" (5.5)

Standard Event Attributes


onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup

Events Defined by Internet Explorer


onactivate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onblur, oncontextmenu, oncontrolselect, oncopy, oncut, ondeactivate, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onfocus, onfocusin, onfocusout, onhelp, onlosecapture, onmouseenter, onmouseleave, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresize, onresizeend, onresizestart, onselectstart, ontimeerror

Examples


Here is some <span style="font-size: 14pt; color: purple">very
strange</span> text.

<span id="toggletext"
 onclick="this.style.color='red'"
 ondblclick=
  "this.style.color='black'">

Click and Double Click Me
</span>

Compatibility


HTML 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 3, 4, 5, 5.5, 6
Netscape 4, 4.5-4.8, 6, 7
Opera 4-7

Notes


The HTML 4.01 specification reserved the datafld, dataformatas, and datasrc attributes for future use. They were later dropped from XHTML. Internet Explorer 4 and later support these attributes for data binding, as discussed in Chapter 7.

As a generic element, span, like div, is useful for binding style to arbitrary content. However, span is an inline element and does not cause a return by default like div.

(X)HTML Elements
CSS Properties
Previous: spacer Next: strike
< Home | About | Chapters | Examples | Errata | Reference | Site Map >