TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HTML button tag

HTML button tag with examples, forms, input, text, anchor, image, heading, marquee, textarea, paragraph, title, quotes, code etc.

<< Back to HTML

HTML Button Tag

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 Now

Output:


HTML 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 TheDeveloperBlog user");
}
</script>
Test it Now

Output:


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

Output:

Enter Name:

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

Output:

Enter Name:

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

AttributeDescription
autofocusIt specifies that a button should automatically get focus while the loading of the page.
disabledIt specifies that a button shuld be disabled.
formIt specifies one or more forms that the button belongs to.
formactionIt is used for submit type. It specifies where to send the form data when form is submitted.
formmethodIt specifies how to send form-data.
formenctypeIt specifies how form-data should be encoded before sending it to server.
formnovalidateIt specifies that the form data should not be validated on submission.
formtargetIt specifies that where to display the response after submitting the form.
nameIt specifies the name of the button.
typeIt specifies the type of the button.
valueIt specifies the value of the button.

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<button>YesYesYesYesYes

HTML button tag also supports the global and event attributes in HTML.

Next TopicHTML canvas Tag




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf