HTML <code> tagS2C Home   « 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 Intermediate - More Text Tags