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

Definition

The <span> tag is a generic container for inline content that allows styling or attribution of that content.

For block-level content use the <div> tag instead.

Example


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

An orange is Orange in colour.

Attributes

The following attributes can be used with the <span> tag.


<span> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <span> tag.
<span> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<span class="name">Text To Style</span>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<span id="name">Text To Style</span>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<span style="color:red;">Text To Style</span>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<span title="Content info">Text To Style</span>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<span accesskey="a">Text To Style</span>
tabindexSpecifies a tab order for the element.

<span tabindex="1">Text To Style</span>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<span dir="ltr">Text To Style</span>
<!-- The text will flow from right to left -->
<span dir="rtl">Text To Style</span>
langSpecifies a language code for the content of the element.

<span lang="en">Text To Style</span>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<span spellcheck="true">Text To Style</span> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<span translate="no">Text To Style</span> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<span contenteditable="true">Text To Style</span> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<span draggable="true">Text To Style</span>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<span hidden>Text To Style</span> 
<span hidden="hidden">Text To Style</span> 
<span> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<span oncopy="go()">Text To Style</span> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<span oncut="go()">Text To Style</span>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<span onpaste="go()">Text To Style</span>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<span ondrag="go()">Text To Style</span>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<span ondragend="go()">Text To Style</span>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<span ondragenter="go()">Text To Style</span>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<span ondragleave="go()">Text To Style</span>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<span ondragover="go()">Text To Style</span>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<span ondragstart="go()">Text To Style</span>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<span ondrop="go()">Text To Style</span>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<span onblur="go()">Text To Style</span>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<span onchange="go()">Text To Style</span>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<span oncontextmenu="go()">Text To Style</span>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<span onfocus="go()">Text To Style</span>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<span oninput="go()">Text To Style</span>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<span oninvalid="go()">Text To Style</span>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<span onreset="go()">Text To Style</span>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<span onselect="go()">Text To Style</span>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<span onsubmit="go()">Text To Style</span>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<span onkeydown="go()">Text To Style</span>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<span onkeypress="go()">Text To Style</span>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<span onkeyup="go()">Text To Style</span>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<span onabort="go()">Text To Style</span>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<span oncanplay="go()">Text To Style</span>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<span oncanplaythrough="go()">Text To Style</span>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<span oncuechange="go()">Text To Style</span>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<span ondurationchange="go()">Text To Style</span>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<span onemptied="go()">Text To Style</span>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<span onended="go()">Text To Style</span>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<span onloadeddata="go()">Text To Style</span>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<span onloadedmetadata="go()">Text To Style</span>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<span onloadstart="go()">Text To Style</span>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<span onpause="go()">Text To Style</span>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<span onplay="go()">Text To Style</span>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<span onplaying="go()">Text To Style</span>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<span onprogress="go()">Text To Style</span>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<span onratechange="go()">Text To Style</span>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<span onseeked="go()">Text To Style</span>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<span onseeking="go()">Text To Style</span>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<span onstalled="go()">Text To Style</span>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<span onsuspend="go()">Text To Style</span>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<span ontimeupdate="go()">Text To Style</span>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<span onvolumechange="go()">Text To Style</span>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<span onwaiting="go()">Text To Style</span>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<span onclick="go()">Text To Style</span>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<span ondblclick="go()">Text To Style</span>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<span onmousedown="go()">Text To Style</span>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<span onmousemove="go()">Text To Style</span>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<span onmouseout="go()">Text To Style</span>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<span onmouseover="go()">Text To Style</span>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<span onmouseup="go()">Text To Style</span>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<span onwheel="go()">Text To Style</span>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<span onscroll="go()">Text To Style</span> 
Window - NONE