HTML5 Reference

HTML <button> tag

Definition

The <button> tag is used to define a button that is clickable by the user within a HTML form or on its own.

Example


<button type="button" onclick="alert('You clicked the button!')">ButtonText</button>

Attributes

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


<button> Specific Attributes
Attribute Value Description Example
autofocus empty string or autofocusGives focus to this control on page load.

<button autofocus>ButtonText</button>
<button autofocus="autofocus">ButtonText</button>
disabledempty string or disabledSpecifies the button will be disabled until a certain condition occurs.

<button disabled>ButtonText</button>
<button disabled="disabled">ButtonText</button>
formform idThe form that the input element belongs to

<button form="formId">ButtonText</button>
formactionurlSpecifies the url of a file that will process the control on submission. Only used with type=submit

<button formaction="url">ButtonText</button>
formenctypeapplication/x-www-form-urlencoded (default)

multipart/form-data

text/plain
Specifies how form-data should be encoded before sending it to a server. Only used with type=submit.

<button formenctype="text/plain">ButtonText</button>
formmethodget

post
Specifies the HTTP method to be used on control submission. Only used with type=submit.

<button formmethod="get">ButtonText</button>
formnovalidateempty string or formnovalidateSpecifies that no validation is to be done on control submission. Only used with type=submit.

<button formnovalidate>ButtonText</button>
<button formnovalidate="formnovalidate">ButtonText</button>
formtarget_blank

_parent

_self

_top

framename

Specifies where to display the response after control submission. Only used with type=submit.

<button formtarget="_self">ButtonText</button>
namenameSpecifies a name for the button.

<button name="aName">ButtonText</button>
typebutton

reset

submit

Specifies the button type.

<button type="submit">ButtonText</button> 
valuetextSpecifies a value for the button.

<button value="aValue">ButtonText</button>
<button> 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.

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

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

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

<button title="Content info">ButtonText</button>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<button accesskey="a">ButtonText</button>
tabindexSpecifies a tab order for the element.

<button tabindex="1">ButtonText</button>
Language
dirSpecifies the directional flow of the content.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<button onscroll="go()">ButtonText</button> 
Window - NONE

Relevant HTML Tutorials

HTML Lessons - Forms