HTML Button Tag - Javatpoint
Có thể bạn quan tâm
The <button> tag is used to create a clickable button within HTML form on your webpage. You can put content like text or image within the <button>........</button> tag.
You should always specify the type attribute for a <button> tag. Different browsers use different default type for the button element.
HTML Button tag can be used inside and outside the form.
If you use it inside the form, it works as the submit button. You can also use it as reset button.
If you use it outside the form, you can call JavaScript function on it.
HTML Button Tag Example
Let's see the code to display the button.
<button name="button" type="button">Click Here</button> Test it NowOutput:
Click HereHTML Button Example: Calling JavaScript Function
Let's see the code to call JavaScript function on button click.
<button name="button" value="OK" type="button" onclick="hello()">Click Here</button> <script> function hello(){ alert("hello javatpoint user"); } </script> Test it NowOutput:
Click HereHTML Button Example: Submit Form
Let's see the code to submit form on button click.
<form> Enter Name:<input type="text" name="name"/><br/> <button>Submit</button> </form> Test it NowOutput:
Enter Name:SubmitHTML Button Example: Reset Form
Let's see the code to submit form on button click.
<form> Enter Name:<input type="text" name="name"/><br/> <button type="reset">reset</button> </form> Test it NowOutput:
Enter Name:ResetAttributes of HTML Button Tag
<button> tag supports all global attributes and some specific additional attributes.
There is given a list of HTML button tag attributes.
Attribute | Description |
---|---|
autofocus | It specifies that a button should automatically get focus while the loading of the page. |
disabled | It specifies that a button shuld be disabled. |
form | It specifies one or more forms that the button belongs to. |
formaction | It is used for submit type. It specifies where to send the form data when form is submitted. |
formmethod | It specifies how to send form-data. |
formenctype | It specifies how form-data should be encoded before sending it to server. |
formnovalidate | It specifies that the form data should not be validated on submission. |
formtarget | It specifies that where to display the response after submitting the form. |
name | It specifies the name of the button. |
type | It specifies the type of the button. |
value | It specifies the value of the button. |
Supporting Browsers
Element | Chrome | IE | Firefox | Opera | Safari |
<button> | Yes | Yes | Yes | Yes | Yes |
HTML button tag also supports the global and event attributes in HTML.
Next TopicHTML canvas Tag← prev next →Từ khóa » Html Button Properties
-
Attributes
-
CSS Buttons - W3Schools
-
The Button Element - HTML: HyperText Markup Language | MDN
-
HTML Button Tag - Usage, Attributes, Examples | W3Docs
-
Learn Attributes Of HTML Button Tag - EduCBA
-
HTML Button Type – How To Add Buttons To Your Website
-
Creating A Button With The HTML Button Element: Here's How »
-
Button Type In HTML: Here's Why You Should Always Declare It »
-
HTML
-
HTML Button Tag - Types, Effects And Attributes - DataFlair
-
Learn HTML Buttons In 5 Minutes 🛎️ - YouTube
-
Ion-button: Design And Style Buttons With Custom CSS Properties
-
HTML | DOM Button Value Property - GeeksforGeeks
-
HTML Button Style Attribute - Dofactory