Little Web Hut

HTML 4.01 and XHTML 1.0 Reference: <button> Tag

HTML <button> Tag
Syntax This element uses separate opening and closing tags.
<button>...</button>
Usage The <button> tag is used to create a button that can contain content. The <button> tag can be used with a <form> tag. The <button> tag can also be used as a stand alone tag which can use a scripting language, like JavaScript, to give it functionality.

HTML <button> example using reset and submit buttons.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test"><br>
 <button type="submit">Send<br>Text</button>
 <button type="reset"><img src="yel.gif" alt="reset"><br>Reset</button>
</p> 
</form>
Test It HTML Style

XHTML <button> example using reset and submit buttons.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test" /><br />
 <button type="submit">Send<br />Text</button>
 <button type="reset"><img src="yel.gif" alt="reset" /><br />Reset</button>
</p> 
</form>
Test It XHTML Style

HTML & XHTML <button> example using button type with JavaScript.
<p>
<button type="button" onclick="window.location='http://www.littlewebhut.com'">
Go To Little Web Hut</button>
</p>
Test It HTML StyleTest It XHTML Style

Content Model The <button> element can contain the following tags, and Text, between its opening and closing tags.Notes:
1. The <button> element can contain the <noframes> tag when using DTD Transitional documents but not Strict or Frameset documents.
2. Red tags have been deprecated and are allowed in DTD Transitional and Frameset documents but not Strict documents.

<button> Tag Attribute Summary
Required Tag Specific Core Focus Events Language
  disabled name value type id class style title accesskey onblur onfocus tabindex onclick ondblclick onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup dir lang xml:lang1
Notes: 1. XHTML only.

<button> Tag Attributes
Attribute Description
disabledThe disabled attribute is used to disable the button so that it cannot be activated.

HTML <button> example using a disabled submit button.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test"><br>
 <button type="submit" name="submit" value="submit" disabled="disabled">Send</button>
 <button type="reset" name="reset"><img src="yel.gif" alt="reset"><br>Reset</button>
</p>
</form>
Test It HTML Style

XHTML <button> example using a disabled submit button.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test" /><br />
 <button type="submit" name="submit" value="submit" disabled="disabled">Send</button>
 <button type="reset" name="reset"><img src="yel.gif" alt="reset" /><br />Reset</button>
</p>
</form>
Test It XHTML Style

nameThe name attribute assigns a name to the control. The name is paired with the value and submitted with the form.

HTML submit button with the name and value attributes.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test"><br>
 <button type="submit" name="submit" value="send_it">send_it</button>
</p> 
</form>
Test It HTML Style

XHTML submit button with the name and value attributes.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test" /><br />
 <button type="submit" name="submit" value="send_it">send_it</button>
</p> 
</form>
Test It XHTML Style

valueThe value attribute assigns a value to the control. The name is paired with the value and submitted with the form.

Note: Some browsers may use the contents of the button element instead of the value attribute. Therefore, consider setting the button element content and the value attribute to the same value to increase browser compatibility.

HTML submit button with the name and value attributes.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test"><br>
 <button type="submit" name="submit" value="send_it">send_it</button>
</p> 
</form>
Test It HTML Style

XHTML submit button with the name and value attributes.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test" /><br />
 <button type="submit" name="submit" value="send_it">send_it</button>
</p> 
</form>
Test It XHTML Style

typeThe type attribute specifies the type of button. Possible values are button, submit, and reset.

The button type creates a button that does not submit a value with the form but instead it can be used with a scripting language, like Javascript, to give it functionality.

The submit type creates a button that is used to submit the form.

The reset type creates a button that resets all of the controls, in the current form, to their initial values.

HTML & XHTML <button> example using button type with JavaScript.
<p>
<button type="button" onclick="window.location='http://www.littlewebhut.com'">
Go To Little Web Hut</button>
</p>
Test It HTML StyleTest It XHTML Style

HTML <button> example using reset and submit buttons.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test"><br>
 <button type="submit">Send<br>Text</button>
 <button type="reset"><img src="yel.gif" alt="reset"><br>Reset</button>
</p> 
</form>
Test It HTML Style

XHTML <button> example using reset and submit buttons.
<form action="example_input.php" method="post">
<p>
 Text: <input type="text" name="texttest" title="test" /><br />
 <button type="submit">Send<br />Text</button>
 <button type="reset"><img src="yel.gif" alt="reset" /><br />Reset</button>
</p> 
</form>
Test It XHTML Style

idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example
classThe class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. See class Example
styleThe style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. See style Example
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example
accesskeyThe accesskey specifies a shortcut key for a tag. The action that is taken when an access key is invoked depends on the tag and may also depend on the browser. For example, if it is used with an <a> tag, some browsers may follow the link when the access key is invoked and other browsers may give focus to the link. See accesskey Example
onblurThe onblur attribute specifies a script to be run when the tag loses focus. See onblur Example
onfocusThe onfocus attribute specifies a script to be run when the tag receives focus. See onfocus Example
tabindexThe tabindex attribute specifies the tabbing position of the tag. The tabbing sequence runs from lower values to higher values. The valid range of values is between 0 and 32767. See tabindex Example
onclickThe onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. See onclick Example
ondblclickThe ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. See ondblclick Example
onkeydownThe onkeydown attribute specifies a script to be run when a key is pressed down. See onkeydown Example
onkeypressThe onkeypress attribute specifies a script to be run when a key is pressed and released. See onkeypress Example
onkeyupThe onkeyup attribute specifies a script to be run when a key is released. See onkeyup Example
onmousedownThe onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. See onmousedown Example
onmousemoveThe onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. See onmousemove Example
onmouseoutThe onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it. See onmouseout Example
onmouseoverThe onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. See onmouseover Example
onmouseupThe onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object. See onmouseup Example
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example

Note: XHTML only.

HTML <button> Tag Examples
Test It HTML StyleTest It HTML Style<button> example using reset and submit buttons.
Test It HTML StyleTest It HTML Style<button> example using button type with JavaScript.
Test It HTML StyleTest It HTML Style<button> example using a disabled submit button.
Test It HTML StyleTest It HTML Stylesubmit button with the name and value attributes.