Versión en español

HTML button tag

Note: If you don't know what a tag is and/or how you must use it we recommend you to read our HTML tags and attributes tutorial that you can find in our HTML tutorials section.

 

Description

The HTML button tag creates a button. It's most common use is to work as a control in forms, but it can also be used to performs actions (through scripts) anywhere. Buttons can also be defined with the HTML input tag, when it's type attribute is "button", but the HTML button tag inserts buttons that allow content. This means that you can put HTML code inside of them.

Attributes

id (name)

The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element.

Example:

Code begin <p id="paragraph1">This is the first paragraph named as paragraph1. To dynamically change its properties use this identifier.</p>Code end
 
 

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used with style sheets and tells the browser the class to which the element is associated with. A class gives visual attributes to elements.

Example:

Code begin <p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>

<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>Code end
 
 

style (style)

Defines a visual style of this element. Is a better practice to define styles attributes in external style sheets grouping them in classes. Attributes in the "style" parameter must preserve this order "name : value" and be separated by a semi-colon.

If you're writing XHTML code it's recommended not to use this attribute and try style sheet classes (with the "class" attribute).

Example:

Code begin <p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style</p>
<p>And this is another text without style.</p>Code end
 
 

title (text)

Indicates a title for the element. Used to give a short description about the element that is usually shown as a "tool tip" when the user put the mouse pointer over the element.

Example:

Code View
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a> HTML code
 

lang (langcode)

Specifies the language of an element's content. The default value in "unknown".

When writing XHTML code the syntax "xml:lang" represents a preferred alternative in XHTML 1.0 and a replacement in XHTML 1.1 (e.g., xml:lang="en").

Example:

Code begin <p lang="en">This is a paragraph in english.</p>
<p lang="es">Este es un p&aacute;rrafo en espa&ntilde;ol.</p>Code end
 
 

dir

Specifies the text direction of the element's contents and attribute values, as well as tables directionality. It has two possible values that are case insensitive:
  • RTL: Right to left.
  • LTR: Left to right.
Example:

Code begin <q lang="he" dir="rtl">...a Hebrew quotation...</q>Code end
 
 

name (cdata)

Assigns a name to the element for further reference. It's recommended to use the "id" attribute instead for XHTML code compatibility.
 

value (cdata)

Assigns the initial value to the element. Depending on the element nature, this value can be changed later by the user.

Example:

Code View
<form action="example.php">
<div>
<input name="firstfield" type="text" value="Here is the initial value" />
</div>
</form>
 

type

Defines the type of the button. It may have one of these case-insensitive values:
  • submit: Creates a submit button (default value). When a submit type button is pressed, the form where it's placed is automatically submited.
  • reset: Creates a reset button. When a reset type button is pressed, all the fields in the form go back to their initial values.
  • button: Creates a push button. This kind of buttons have no default action associated. Are usually defined with custom scripts to handle it's events.
 

disabled

When this attribute is set, the control is disabled, this means than it cannot get the focus, it's value cannot be changed and it will not be submitted with the form. Dependign on the browser, disabled element may be shown different.

Example:

Code View
<form action="example.php">
<div>
<input name="firstbutton" type="button" value="This is not disabled" /><br /><br />
<input name="secondbutton" type="button" value="This is disabled" disabled="disabled" /><br /><br />
<input name="secondtext" type="text" value="This is not disabled" /><br /><br />
<input name="firsttext" type="text" value="This is disabled" disabled="disabled" />
</div>
</form>






 

tabindex (number)

Specifies the position of this element in the tabbing order. The tabbing order defines the sequence with all the elements than can receive the focus. Users can navigate this sequence via keyboard (usually with the "tab" key).
 

accesskey (character)

Stablish a relationship between this element and a character key, allowing the user to activate it with that key (usually when used together with the "alt" key). The activation result depends on the actual element's nature. For links, this action automatically follows the link, and other elements simply get the focus.
 


Events

  • onfocus
  • onblur
  • onclick
  • ondblclick
  • onmousedown
  • onmouseup
  • onmouseover
  • onmousemove
  • onmouseout
  • onkeypress
  • onkeydown
  • onkeyup
See complete list and information about events in HTML


Examples

Using two kind of buttons to show the same result.

Code View
<form action="eg.php">
<div>
<input type="button" name="firstbutton" value="Input button" /><br /><br />
<button type="button" name="secondbutton">Button button</button>
</div>
</form>



Button allowing content.

Code View
<form action="eg.php">
<div>
<button type="button" name="contentbutton">
<img src="http://www.htmlquick.com/img/links/button.jpg" width="88" height="31" alt="HTMLQuick.com link button" /><br />
<b>Nice button!</b>
</button>
</div>
</form>

Bypass footer options Send to a friend Send to a friend