HTML <button> Definition, Usage and Examples

The <button> HTML Tag signifies a clickable button that can be used to submit forms or to provide accessible, standard button functionality throughout a document. By default, HTML buttons are styled to match the platform on which the user agent runs, but you can customize their appearance using CSS. The <button> HTML Tag is part of the Forms and Input HTML category in HTML Element Reference. The attributes of the <button> HTML Tag are autofocus, disabled, form, formaction, formenctype, formmethod, formnovalidate, formtarget, name, type, value, global, and event attributes. 

<button> code block example to learn how it works is given below. 

<button>Click here</button>

The second example usage of the “<button>” code block example is given below. 

<button type = "button" onclick = 
            "alert('Welcome')">
            Click Me
        </button>

What is <button> HTML Tag?

The <button> HTML Tag is used to define a clickable button. The content is submitted using the <button> HTML Tag. Images and text content can be contained within the <button> HTML Tag. Different browsers use a variety of different default button types. CSS can be used to style buttons.

How to Use <button> HTML Tag?

To use <button> HTML Tag, the web developer should create <button></button> insert the content text between the start and end tags. The content text serves as the label for the button. The <button> HTML Tag accepts a number of attributes that allow you to customize the appearance, behavior, and other properties of the button.

Example Usage of <button> HTML Tag?

The following example of usage of <button> HTML Tag is given below.

<button type = "button" onclick = 
            "alert('GET STARTED')">
            Click Here
        </button>

What are the Attributes of <button> HTML Tag?

There are multiple attributes for the <button> HTML Tag. The following attributes are listed below.

  • autofocus attribute: The <button> HTML Tag supports autoplay attribute. The autofocus attribute is used to specify whether or not the button should receive focus automatically when the page loads.
  • disabled attribute: The <button> HTML Tag supports disabled attribute. The disabled attribute specifies whether an element is disabled or not.
  • form attribute: The <button> HTML Tag supports form attribute. The form attribute is used to define a user-input form.
  • formaction attribute: The <button> HTML Tag supports formaction attribute. A user input form is created using the formaction attribute.
  • formnovalidate attribute: The <button> HTML Tag supports formnovalidate attribute. The formnovalidate attribute instructs the browser not to validate the Input Element during form submission.
  • formenctype attribute: The <button> HTML Tag supports formenctype attribute. The formenctype attribute specifies whether or not form data should be encoded before being submitted to the server.
  • formmethod attribute: The <button> HTML Tag supports formmethod attribute. The formmethod attribute specifies the HTTP method used to send data when the form is submitted.
  • formtarget attribute: The <button> HTML Tag supports formtarget attribute. The formtarget attribute is used to specify a name or a keyword that indicates where the response should be displayed after the form is submitted.
  • type attribute: The <button> HTML Tag supports type attribute. The type attribute is used to specify the button element’s type.
  • value attribute: The <button> HTML Tag supports value attribute. The value attribute is used to specify the value of the containing element. It has a variety of different meanings for various HTML Tags.
  • Global Attributes: The <button> HTML Tag supports Global Attributes. All HTML elements, even those not specified in the standard, can have global attributes. This means that any non-standard elements must nevertheless allow certain characteristics, even if using such elements makes the content non-HTML5 compliant.
  • Event Attributes: The <button> HTML Tag supports Event Attributes. The Event Attributes always have a name that begins with “on” and is followed by the name of the event for which it is intended. They specify a script to run when an event of the defined type is dispatched to the element with the specified attributes.

What are the Default CSS Settings for <button> HTML Tag?

The following are the Default CSS Settings for the <button> HTML Tag.

.styled {
    border: 0;
    line-height: 2.5;
    padding: 0 20px;
    font-size: 1rem;
    text-align: center;
    color: #fff;
    text-shadow: 1px 1px 1px #000;
    border-radius: 10px;
    background-color: rgba(220, 0, 0, 1);
    background-image: linear-gradient(to top left,
                                      rgba(0, 0, 0, .2),
                                      rgba(0, 0, 0, .2) 30%,
                                      rgba(0, 0, 0, 0));
    box-shadow: inset 2px 2px 3px rgba(255, 255, 255, .6),
                inset -2px -2px 3px rgba(0, 0, 0, .6);
}

.styled:hover {
    background-color: rgba(255, 0, 0, 1);
}

.styled:active {
    box-shadow: inset -2px -2px 3px rgba(255, 255, 255, .6),
                inset 2px 2px 3px rgba(0, 0, 0, .6);
}

What are the Related other HTML Tags to <button>?

The other related HTML Tags to <button> HTML Tag are listed below.

  • <form> HTML Tag: The <form> HTML Tag is related to <button> HTML Tag because they are both forms and input tags. Forms are created using the <form> HTML Tag.
  • <input> HTML Tag: The <input> HTML Tag is related to <button> HTML Tag because they are both forms and input tags. The <input> HTML Tag is used to specify the Input Element.
  • <textarea> HTML Tag: The <textarea> HTML Tag is related to <button> HTML Tag because they are both forms and input tags. The HTML Tag <textarea> is used to specify a text input element.
  • <select> HTML Tag: The <select> HTML Tag is related to <button> HTML Tag because they are both forms and input tags. The <select> HTML Tag is used to define drop down list.
  • <optgroup> HTML Tag: The <optgroup> HTML Tag is related to <button> HTML Tag because they are both forms and input tags. The <optgroup> HTML Tag denotes a group of options in a drop-down list.
Holistic SEO
Follow SEO

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.