HTML5 Reference

HTML <code> tag

Definition

The <code> tag is used to define computer code in text.

Example


<p>The following JavaScript is displayed as computer code.</p>
<code>var current_date = new Date( );</code>

The following JavaScript is displayed as computer code.

var current_date = new Date( );

Attributes

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


<code> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <code> tag.
<code> 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.

<code class="name">Computer code text</code>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<code id="name">Computer code text</code>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<code style="color:red;">Computer code text</code>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<code title="Content info">Computer code text</code>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<code accesskey="a">Computer code text</code>
tabindexSpecifies a tab order for the element.

<code tabindex="1">Computer code text</code>
Language
dirSpecifies the directional flow of the content.

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

<code lang="en">Computer code text</code>
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. -->
<code spellcheck="true">Computer code text</code> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<code translate="no">Computer code text</code> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<code contenteditable="true">Computer code text</code> 
draggableSpecifies whether the element is draggable.

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

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

 <!-- Executes go() function -->
<code oncopy="go()">Computer code text</code> 
oncutThe script to be run when the user cuts the content of an element.

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

 <!-- Executes go() function -->
<code onpaste="go()">Computer code text</code>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<code ondrag="go()">Computer code text</code>
ondragendThe script to be run when an element has stopped being dragged.

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

 <!-- Executes go() function -->
<code ondragenter="go()">Computer code text</code>
ondragleaveThe script to be run when an element leaves a valid drop target.

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

 <!-- Executes go() function -->
<code ondragover="go()">Computer code text</code>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<code ondragstart="go()">Computer code text</code>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<code ondrop="go()">Computer code text</code>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<code onblur="go()">Computer code text</code>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<code onchange="go()">Computer code text</code>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<code oncontextmenu="go()">Computer code text</code>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<code onfocus="go()">Computer code text</code>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<code oninput="go()">Computer code text</code>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<code oninvalid="go()">Computer code text</code>
onresetThe script to be run when a dragged element is being dropped.

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

 <!-- Executes go() function -->
<code onselect="go()">Computer code text</code>
onsubmitThe script to be run when a form is submitted.

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

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

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

 <!-- Executes go() function -->
<code onkeyup="go()">Computer code text</code>
Media
onabortThe script code to be run on abort.

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

 <!-- Executes go() function -->
<code oncanplay="go()">Computer code text</code>
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 -->
<code oncanplaythrough="go()">Computer code text</code>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<code oncuechange="go()">Computer code text</code>
ondurationchangeThe script to be run when the length of the media is changed.

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

 <!-- Executes go() function -->
<code onemptied="go()">Computer code text</code>
onendedThe script to be run when the media has reach the end.

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

 <!-- Executes go() function -->
<code onloadeddata="go()">Computer code text</code>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<code onloadedmetadata="go()">Computer code text</code>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<code onloadstart="go()">Computer code text</code>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<code onpause="go()">Computer code text</code>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<code onplay="go()">Computer code text</code>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<code onplaying="go()">Computer code text</code>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<code onprogress="go()">Computer code text</code>
onratechangeThe script to be run when the playback rate changes.

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

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

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

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

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

 <!-- Executes go() function -->
<code ontimeupdate="go()">Computer code text</code>
onvolumechangeThe script to be run when the volume has changed or been muted.

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

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

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

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

 <!-- Executes go() function -->
<code onmousedown="go()">Computer code text</code>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<code onmousemove="go()">Computer code text</code>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<code onmouseout="go()">Computer code text</code>>
onmouseoverThe script to be run when the mouse cursor moves over an element.

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

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

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

 <!-- Executes go() function -->
<code onscroll="go()">Computer code text</code> 
Window - NONE

Relevant HTML Tutorials

HTML Lessons - Text