A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/html/elements/button below:

button · WebPlatform Docs

button Summary

The button element represents a clickable button.

Overview Table
DOM Interface
HTMLButtonElement

You can put text or images inside a button element. If the element is not disabled, the user can activate the button.

By default, the button element is used to submit form data. Modifying the type attribute can change this behavior.

Attributes (HTML 4)
name
The name of the button. This can be used to identify which button was used to submit a form.
type
This specifies the type of the button. If omitted, the type is submit. The following types are possible:
value
The initial value of the button.
disabled
This Boolean attribute indicates that the user cannot interact with the button. If this attribute is not specified, the button inherits its setting from the containing element, for example fieldset if there is no containing element with the disabled attribute set, then the button is enabled. A disabled button isn’t clickable.
Additional attributes (HTML 5, candidate specification)
autofocus

When this attribute is set to “true” the button will have input focused after the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified.
form

Specifies which form the button is associated with. The value of the attribute must be the id attribute of the form. If this attribute is not specified, the button must be a descendant of the form itself to be able to submit form data. This attribute enables you to place button elements anywhere within a document, not just as descendants of their form elements.
formaction

The URI of a program that processes the information from the form. When present, it will override the action attribute of the associated form.
formmethod

The HTTP method to send the form data. This can either be post or get. If specified, it will override the method attribute of the associated form. Possible values are:

formnovalidate

If the button is a submit button, this attribute specifies whether the form should be validated or not. It overrides the novalidate attribute of the form it belongs to.
formtarget

This attribute is a keyword, indicating where to display the response that is received after submitting the form. This can be one of the following:

All these attributes, except name, have default values and can be omitted.

Examples

This examples uses the <button> element to display a clickable button with out sending or reseting a form.

<button name="myButton" type="button">Click me</button>

View live example

This example shows how to use a submit <button> to send a form. Read about the form element to get further information about how to use forms.

<form action="dataReceiverURI">
  <label for="name">Name:</label>
  <input id="name" type="text" name="user_name">
  <button name="mySubmitButton">Submit</button>
</form>

View live example

This example shows how to reset a form with use of <button="reset">. Read about the form element to get further information about how to use forms.

<form>
  <label for="name">Name:</label>
  <input id="name" type="text" name="user_name" >
  <button name="myResetButton">reset</button>
</form>

View live example

Usage
 Generally, the button element can be used whenever there should be a button clickable by the user.

The ending tag is mandatory. The button should have a descriptive text inside it, otherwise the button will be empty and the user won’t know what the button will do.

Please note that styling a submit button using the <button> element is easier than styling an input element with type submit.

Notes

Since the default for the type attribute is submit, the type can be omitted if no other type needs to be used. Historical browser versions may have different standard type values.

Firefox for Android, by default, sets a background-image gradient on all button elements. This can be disabled using background-image: none.

Firefox will, unlike other browsers, by default, persist the dynamic disabled state of a button across page loads. Setting the value of the autocomplete attribute to off disables this feature. See Mozilla Bug #654072.

Clicking and focus

Whether clicking on a button causes it to (by default) become focused varies by browser and OS.

Does clicking on a button give it the focus?:

Desktop Browsers Windows 8.1 OS X 10.9 Firefox 30.0 Yes No (even with a tabindex) Chrome 35 Yes Yes Safari 7.0.5 N/A No (even with a tabindex) Internet Explorer 11 Yes N/A Presto (Opera 12) Yes ???

Does tapping on a button give it the focus?:

Mobile Browsers iOS 7.1.2 Android 4.4.4 Safari Mobile No (even with a tabindex) N/A Chrome 35 ??? Yes Related specifications
HTML 5.1
W3C Working Draft
HTML 5
W3C Recommendation
HTML 4.01
W3C Recommendation
See also Related articles Document Structure HTML Other articles Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4