Menu

HTML button Tag

HTML button Tag

The HTML <button> tag is used to create a clickable button on the webpage which can be used to perform some action or as an action button for HTML form. A button can be used to perform various tasks like submitting or resetting the details of the form, can be used for a hyperlink, etc., in short, if you are building a webpage and you want to have a button on your webpage you can use use the <button> tag for it.

  • <button> tag is generally used with the <form> tag to display the controls of the form.
  • We can also use the <input> tag for creating a submit button for HTML form, but then you cannot change the appearance of the button and can only change the text value which appears on the button.
  • The text, images, or any multimedia embedded in between the opening and closing tag of a button becomes content of the button.
  • Also, this is an inline element.
  • The <button> tag provides a type attribute using which you can create three kinds of button controls and these are: Submit button, reset button, and normal button.

Three kinds of Button:

  1. Submit Button: created by setting the type attribute to submit
  2. Reset Button: created by setting the type attribute to reset
  3. Normal Button: created by setting the type attribute to button

HTML <button> Tag - Syntax and Usage

The <button> element requires the start(opening) tag and end(closing) tag.

The Required syntax for the same is given below:

<button>
    <!-- Some content -->
</button>

HTML <button> Tag Attributes

HTML <button> tag supports Global attributes and Event attributes. Some of the common attributes used with the <button> tag are given below:

AttributesDescription
autofocusallows the button control to get the focus as soon as the page loads.
formThe form is used to refer to the id of the FORM element.
formtargetSpecifies the destination such as a new tab, or a new window to load the browsing content.
formnovalidateThis specifies that there is no need to validate the form at the time of submitting the button control.
formmethodspecifies the method at the time of submitting the button control. The possible values are: get, post, put and delete.
formenctypeThis attribute is used to specify the type of content that is used to submit the form to the browser
nameThis attribute specifies the name of the button which is submitted with the form data
typeThis attribute is used to specify the type of button and its values are:- submit, reset and normal.
valueThis attribute is used to define the initial value of the button. This initial value is passed to the server in the params when the form is submitted.
autocompleteThe use of this attribute on a <button> is non-standard and firefox specific.
disabledThis attribute indicates that the user cannot interact with the button.

HTML <button> Tag Basic Example

Below we have a basic example for a clear understanding of <button> tag:

<!DOCTYPE HTML>
<html>
    <head>
        <title>
            Using the BUTTON element
        </title>
    </head>
    <body>
        <p>This is simple submit button used as hyperlink:</p>
        <a href="https://studytonight.com" target="_blank"><button>SUBMIT</button></a>
        <HR/>
        <p>Changing the button text</p>
        <button style="color:#6a67ce;font-size:20px;"><b>SUBMIT</b></button>
    </body>
</html>

Default CSS styling for <button> tag:

None

Browser Support for HTML <button> tag

Following browsers support this attribute:

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 4+
  • Apple Safari 1+
  • Opera 5+