HTML <span> tagS2C Home   « HTML <span> tag

Definition

The <span> tag doesn't affect our web page directly but is generally used to group some inline HTML together for styling with CSS.

Example


  <p>An orange is <span style="color:orange">Orange</span></p>

Required Attributes

NONE

Optional Attributes

NONE

Common Attributes

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<span class="classname">Text to style here</span>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<span id="idname">Text to style here</span>

style - specifies an inline style for the element allowing you to apply the style to the content.


<span style="color:red;text-align:left">Text to style here</span>

title - specifies extra information about the content.


<span title="information about the content">Text to style here</span>

Language Attributes

dir - specifies the directional flow of the content.


<!-- The text will flow from left to right -->
<span dir="ltr">Text to style here</span>

<!-- The text will flow from right to left -->
<span dir="rtl">Text to style here</span>

lang - specifies a language code for the content of the element.


<span lang="en">Text to style here</span>

xml:lang - specifies a language code for the content of the element in XHTML documents.


<span xml:lang="fr">Text to style here</span>

Document Event Attributes

NONE

Form Event Attributes

NONE

Image Event Attributes

NONE

Keyboard Event Attributes

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<!-- Executes the go() function -->
<span onkeydown="go()">Text to style here</span>

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<!-- Executes the go() function -->
<span onkeypress="go()">Text to style here</span>

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<!-- Executes the go() function -->
<span onkeyup="go()">Text to style here</span>

Mouse Event Attributes

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<!-- Executes the go() function -->
<span onclick="go()">Text to style here</span>

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<!-- Executes the go() function -->
<span ondblclick="go()">Text to style here</span>

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<!-- Executes the go() function -->
<span onmousedown="go()">Text to style here</span>

onmousemove - The JavaScript code to be run when the mouse button is moved.


<!-- Executes the go() function -->
<span onmousemove="go()">Text to style here</span>

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<!-- Executes the go() function -->
<span onmouseout="go()">Text to style here</span>

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<!-- Executes the go() function -->
<span onmouseover="go()">Text to style here</span>

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<!-- Executes the go() function -->
<span onmouseup="go()">Text to style here</span>

go to home page Homepage go to top of page Top