Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > HTML Tags > HTML button tag

Bypass main content

HTML button tag

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

Bypass main content

Description

The HTML button tag inserts a button control in a form or document. Differently from the HTML input element using "button" in the "type" attribute, this button can contain other elements (i.e., HTML code).

Note: The behavior of the interactive content displayed inside an HTML button element varies from browser to rowser.

Examples

Code
<button type="button">
<p><strong>HTML content</strong> is allowed in this button</p>
<p>See also the <a href="http://www.htmlquick.com/reference/tags/input.html">HTML input element</a>.</p>
</button>
View

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 in other instances (e.g., from client-side scripts).

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

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It is used together with style sheets and tells the browser the class (or classes) to which the element is associated.

A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).

<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>

style (style)

This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although in some cases it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.

You can find more information about presentational attributes at the Cascading Style Sheets tutorial.

<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>

title (text)

The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a short period of time.

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

lang (langcode)

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

When writing XHTML 1.0 documents, the attribute used to specify the language of an elements is "xml:lang". For forward and backward compatibility both attributes can be used simultaneously as in the example below. Note, that in XHTML 1.1 the "lang" attribute has been completely replaced by "xml:lang" and its use is no longer valid.

<p lang="en" xml:lang="en">This is a paragraph in English.</p>
<p lang="es" xml:lang="es">Este es un párrafo en español.</p>

dir

This attribute indicates the direction in which the texts of the element must be read. This includes content, attribute values and tables. It has two possible values that are case-insensitive:

  • RTL: Right to left.
  • LTR: Left to right.
<q lang="he" dir="rtl">...an Hebrew quotation...</q>

name (cdata)

This attribute gives a name to the element for future reference. This name will identify the element when the processing agent processes the form.

It can also be used to refer to the element from a client-side script, as a sub-element of the containing form.

Input your first name: <input name="firstname" type="text" />

value (cdata)

Assigns the initial value in a form's control. Depending on the element's nature, this value can be changed later by the user.

Code
<form action="example.php">
First field: <input name="firstfield" type="text" value="This is the initial value" />
</form>
View
First field:

type

This attribute decides the default action of the button. It may have one of these case-insensitive values:

  • submit: Creates a submit button. When a submit type button is pressed, the form where it is placed is automatically submitted.
  • 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. They are usually controled by custom scripts that handle their events.

disabled

When this attribute is present, the control is disabled. This means than it cannot get the focus, it's value cannot be changed and it won't be submitted with the form. Depending on the browser, disabled elements may be redenred differently.

This is a boolean attribute, which means that can only have two values: true or false. Because of this is commonly used without value (nor the equal sign and the quotes). But when writing correct XHTML code, boolean attributes must be defined with their names for value (bool_attr="bool_attr").

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


tabindex (number)

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

<a href="doc1.html" tabindex="1">First document in the list</a>
<a href="doc2.html" tabindex="2">Second document in the list</a>
<a href="doc3.html" tabindex="3">Third document in the list</a>

accesskey (character)

Relates the element to a character key. Most browsers allow users to access the element by pressing that key while holding down the "alt" key. The activation result depends on the element's nature. For links, this action automatically follows the link, while other elements simply get the focus.

<a href="http://www.htmlquick.com/" accesskey="H">Homepage</a>

Events

  • onfocus
  • onblur
  • onclick
  • ondblclick
  • onmousedown
  • onmouseup
  • onmouseover
  • onmousemove
  • onmouseout
  • onkeypress
  • onkeydown
  • onkeyup

See a complete list and information about events in HTML

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate