HTML

Skip to content geeksforgeeks
  • Courses
    • DSA Courses
    • Programming Languages
  • Tutorials
    • Python Tutorial
      • Python Data Types
      • Python Loops and Control Flow
      • Python Data Structures
      • Python Exercises
    • Java
      • Java Programming Language
        • OOPs Concepts
      • Java Collections
      • Java Programs
      • Java Interview Questions
      • Java Quiz
      • Advance Java
    • Programming Languages
    • System Design
      • System Design Tutorial
    • Interview Corner
    • Computer Science Subjects
    • DevOps
    • Linux
    • Software Testing
    • Databases
    • Android
    • Excel
    • Mathematics
  • DSA
    • Data Structures
      • Linked List
      • Tree
    • Algorithms
      • Analysis of Algorithms
      • Searching Algorithms
      • Sorting Algorithms
    • Practice
      • Company Wise Coding Practice
      • Practice Problems Difficulty Wise
      • Language Wise Coding Practice
      • Curated DSA Lists
    • Company Wise SDE Sheets
    • DSA Cheat Sheets
    • Puzzles
  • Data Science
    • Data Science Packages
    • Data Visualization
    • Data Analysis
  • Web Tech
    • Web Development Using Python
      • Django
      • Flask
    • Cheat Sheets
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App HTML button Tag Last Updated : 20 Nov, 2024 Summarize Comments Improve Suggest changes Like Article Like Save Share Report Follow

The <button> tag in HTML is used to create clickable buttons on a web page. It can be used to submit forms, trigger JavaScript functions, or perform other interactive tasks.

HTML <!DOCTYPE html> <html> <body> <button type="button" onclick="alert('Welcome to GeeksforGeeks')"> Click Here </button> </body> </html>

Note:

  • It is important to specify the type attribute for a button element to inform the browser of the button’s function.
  • The HTML <button> tag supports the Global Attribute and Event Attribute in HTML.

Attributes:

The various attributes that can be used with the “button” tag are listed below:

Attributes

Descriptions

autofocus

Sspecifies whether the button should automatically get focus or not when the page loads

disabled

indicate whether the element is disabled or not. If this attribute is set, the element is disabled.

form

Create a form for user input. There are many elements that> are used within the >form tag.

formaction

Sspecifies where to send the data of the form.

formnovalidate

Sspecifies that the Input Element should not be validated when submitting the form.

formenctype

Sspecifies that the form data should be encoded when submitted to the server.

formmethod

Sspecifies the HTTP method used to send data while submitting the form.

formtarget

Sspecifies the name or a keyword that indicates where to display the response after submitting the form.

type

Sspecifies the type of button for button elements. It is also used in <input> element to Sspecifies the type of input to display.

value

Sspecifies the value of the element with which it is used. It has different meanings for different HTML elements.

Button with custom CSS

HTML <!DOCTYPE html> <html lang="en"> <head> <style> button{ padding:10px20px; font-size:16px; margin-top:40px; border:none; cursor:pointer; border-radius:4px; transition:background-color0.3sease; color:#fff; } </style> </head> <body> <button style="background-color: #3daaf3; ">Primary</button> <button style="background-color: #3bda7d; ">Secondary</button> <button style="background-color: #f08f3b; ">Warning</button> <button style="background-color: #e44331; ">Danger</button> </body> </html>

HTML button Tag – FAQ’s

What are the different types of buttons available with the <button> tag?

The <button> tag supports three types via the type attribute: button, submit, and reset. By default, it’s type=”submit” if not specified.

What’s the difference between the <button> and <input type=”button”> tags?

The <button> tag is more flexible as it can contain HTML content (like images or text), while <input type=”button”> is limited to plain text.

How do you disable a button using the <button> tag?

You can disable a button by adding the disabled attribute: <button disabled>Disabled Button</button>. Disabled buttons are unclickable and appear grayed out.

Can the <button> tag contain other HTML elements?

Yes, the <button> tag can contain other elements like <span>, <img>, or even formatted text for more complex button designs.

How does the form attribute work with the <button> tag?

The form attribute links a button to a specific form by Sspecifiesing the form’s ID, allowing buttons to submit forms outside the form’s immediate scope.

S

sheyakhare1999 Follow Improve Previous Article HTML <br> Tag Next Article HTML <caption> Tag

Similar Reads

button tag vs input type="button" attribute The <input type="button"> and <button> tag are two different approach to use Button in HTML document. The difference between them is that the buttons created with the <button> tag offer many contributing possibilities than <input type="button"> attribute. The <button> can have content inside it. The <button> tag 2 min read Which tag is used to represent progress of a task in HTML & how is it different from <meter> tag ? In this article, we will see which tag is used to represent the progress of a task in HTML. To represent the progress of a task, we will use the <progress> tag. This tag is used to represent the progress of a task. It is also defined how much work is done and how much is left. Syntax: <progress attributes...> </progress> Attribute 2 min read Is container tag same as the empty tag in HTML? If not, why ? In this article, we will see the container tag & empty tag in HTML, along with knowing how they're different from each other. The Container tag is not the same as the empty tag & these are two different categories of tags used in HTML. Container tag: This tag contains 3 parts, namely, the opening tag, content that will be displayed in the b 5 min read How to trigger HTML button after hitting enter button in textbox using JavaScript ? In this article, we are given an HTML document containing a text area and the task is to trigger the button when the user hit Enter button. We can do it by using the "keyup", "keydown", or "keypress" event listener on the textbox depending on the need. When this event is triggered, we check if the key pressed is ENTER or not. If the key pressed is 4 min read Why <big> tag is not in HTML5 while <small> tag exists ? The <big> tag was discontinued in HTML5 while <small> tag is still in handy because <small> tag is frequently used to represent small prints like footnotes, copyright notices, comments etc. Many alternatives for <big> tag are already available such as <h1>, <h2> and so on. In HTML5 instead of using <big>, y 2 min read Explain the difference between head Tag and header Tag in HTML5 ? The <head> element is a container for metadata and is placed between the <html> and <body> tags. The <header> is for the main content section's introductory elements, like headings or logos and it mainly focuses on what appears at the top of the webpage. <head> ElementThe <head> element is part of the HTML docume 1 min read What is the difference between the <br> Tag and the <p> Tag ? The <br> tag is used to insert a line break, creating a new line within text or content. It doesn't have a closing tag and is a self-closing tag. On the other hand, the <p> tag defines a paragraph, separating blocks of text. It has an opening <p> and a closing </p> tag, allowing for the structured organization of text into p 2 min read Difference between <article> tag and <section> tag Both the tags are semantics in HTML 5. In this article, we will discuss about the <article> and <section> tag. Both the <article> and <section> tags are represented similarly but used for some meaning, that meaning is for the browsers and the developers. Both tags can replace each other as there will be no changes to the out 4 min read What purpose does a <script> tag serve inside of a <noscript> tag? Usage of NoScript tag: The tag defines alternate content that will be displayed if the user has disabled script or browser does not support script. It can be used inside both <head> and <body> tag. Syntax: <noscript> Contents... </noscript> Example: [GFGTABS] HTML <html> <head> <title>wbr Tag</title> 1 min read How to change the href value of a tag after click on button using JavaScript ? JavaScript is a high-level, interpreted, dynamically typed, and client-side scripting language. HTML is used to create static web pages. JavaScript enables interactive web pages when used along with HTML and CSS. Document Object Manipulation (DOM) is a programming interface for HTML and XML documents. DOM acts as an interface between JavaScript and 4 min read How to use Anchor tag as submit button ? The <a> (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages. It’s either used to provide an absolute reference or a relative reference as its “href” value. Syntax: <a href = "link"> Link Name </a> The href attribute specifies the URL of the page the link 3 min read How to Hide Full Screen Button of the Video Tag in HTML5 ? The <video> element is used to embed video content on the web page. It allows the addition of video files in many formats such as MP4, WebM, etc. This element supports attributes like controls, autoplay, and loop to control video playback. It also enables the addition of captions and subtitles for accessibility. Preview: Approach:Create a str 1 min read How to create a radio button similar to toggle button using Bootstrap ? Toggle Buttons: The buttons that can change from one state to another, i.e. which can be toggled from on state to off state or vice-versa are called toggle buttons. For example: A particular switch in our house can either be on or off. This is a very good example of a real life toggle switch. The WiFi or Bluetooth option in our phone is another exa 3 min read How to set radio button checked by button click in AngularJS ? In this article, we will see how to set the radio button checked by button click in AngularJS, along with knowing its implementation through the examples. Approach: The approach is to use the ng-checked directive to check the radio button in the DOM. In the first example, a single radio button is checked by the button and In the second example, mul 2 min read Angular PrimeNG Button Properties of p-button Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to style the Tooltip component in Angular PrimeNG. A Button is generally used for carrying out some action when clicked. 5 min read HTML <html> Tag HTML is a language full of diverse elements, and one such element is the <html> tag. This tag, standing for ‘HyperText Markup Language’, is used to define the root of an HTML or XHTML document. It serves as the main container for all other HTML elements, excluding the <!DOCTYPE> declaration. Understanding the <html> TagThe <htm 3 min read HTML | <noframes> Tag The <noframes> tag is the backup for those browsers that does not support frames. This tag can contains all the element that can be placed in <body> tag. It is used to create link with the non-frame set version of any website where you want to display a message to the user. This <noframes> tag is not supported in HTML5. Syntax: 1 min read HTML <hgroup> Tag The <hgroup> tag in HTML stands for heading group and is used to group the heading elements. The <hgroup> tag in HTML is used to wrap one or more heading elements from <h1> to <h6>, such as the headings and sub-headings. The <hgroup> tag requires the starting tag as well as ending tag. Note: <hgroup> is deprecate 1 min read HTML | <bgsound> tag The HTML <bgsound> tag is used to play the soundtrack in the background, when you leave the page behind and open a new tab this tag will continuously play the track in the background. This tag is not for other browsers except the Internet Explorer. It does not display any graphical interface just played the track in the background. Syntax: 1 min read HTML | <isindex> tag The <isindex> tag is used to querying any document through a text field. Means this tag inform the browser that the user wants to provide the search function through the document. If you want to search any specific word in a long article this tag is helpful then. But during these days all the browsers contain that feature by pressing CTRL + F 2 min read Differences between HTML <center> Tag and CSS "text-align: center;" Property If you are designing a simple web page, then not much difference is noticeable, but it is very necessary to understand the basic differences between these two. Since we are only concerned with the text, these elements do not have separate meanings.HTML <center> tag: The <center> tag in HTML is used to set to align of text into the cente 3 min read How to validate HTML tag using Regular Expression Given string str, the task is to check whether it is a valid HTML tag or not by using Regular Expression.The valid HTML tag must satisfy the following conditions: It should start with an opening tag (<).It should be followed by a double quotes string or single quotes string.It should not allow one double quotes string, one single quotes string o 6 min read How to get all HTML content from DOMParser excluding the outer body tag ? DOM (Document Object Model) allows us to dynamically access and manipulate the HTML data. All the text data from an HTML file can also be extracted using DOMParser. DOM parser returns an HTML/XML/SVG object. All the objects can be accessed using the [ ] operator in javascript. The HTML DOM Tree of objects: Steps to get all the text from an HTML doc 2 min read HTML sup Tag The <sup> tag in HTML describes the text as a superscript text. Here the text is above the baseline of the text and that text appears in a smaller font. Syntax: <sup> Content... </sup> Example 1: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;HTML sup Tag&lt;/title&g 1 min read How to draw a circle using SVG tag in HTML ? In this article, you will learn about SVG basic shape like circle which is among the different shapes of SVG like <rect>, <line>, <ellipse>, <polygon>, etc. So you can easily draw circles using <circle> tag whose parent tag is SVG tag in HTML. Basically, the <circle> element draws a circle on the screen which is 2 min read Explain the significance of <head> and <body> tag in HTML The HTML <head> and <body> tags are the two most commonly used tags in HTML. It is very rare to find an industry-level website that does not use the <head> and <body> tag in its pages. In this article, we are going to learn the significance of these two tags in an HTML document. Significance of HTML <head> tag: The hea 3 min read HTML <slot> Tag The slot is the element part of the web component technology which is a placeholder inside a component that you simply can fill together with your own markup, which allows you to make separate DOM trees and represent them together. Syntax: <slot> <h1>Heading</h1> </slot> Attributes: name: It describes the name of the slot. A 2 min read What is the use of <legend> tag in HTML ? In this article, we will discuss <legend> tag in HTML. The legend tag is used to define the title for the child's contents. The legend elements are the parent element. This tag is used to define the caption for the <fieldset> element. Syntax: <legend> Some Text...... </legend> Example 1: In this example, we are going to crea 1 min read Which specific tag is used to represent the article in HTML ? In this article, we will see how to represent the article in HTML. The <article> tag is one of the new sectioning element in HTML5. The HTML <article> tag is used to represent an article. More specifically, the content within the <article> tag is independent of the other content of the site (even though it can be related). In othe 2 min read Which tag is used to define the abbreviation of an element in HTML ? In this article, we will discuss the tag that is used to define an abbreviation. The <abbr> tag in HTML is used to define the abbreviation or the short form of an element. The <abbr> and <acronym> tags are used as shortened versions and used to represent a series of letters. The abbreviation is used to provide useful information t 1 min read Article Tags :
  • HTML
  • Technical Scripter
  • Web Technologies
  • HTML-Tags
  • Technical Scripter 2018
+1 More Like three90RightbarBannerImg Explore More We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It ! Lightbox Improvement Suggest changes Suggest Changes Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal. geeksforgeeks-suggest-icon Create Improvement Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all. geeksforgeeks-improvement-icon Suggest Changes min 4 words, max CharLimit:2000

What kind of Experience do you want to share?

Interview Experiences Admission Experiences Career Journeys Work Experiences Campus Experiences Competitive Exam Experiences

Từ khóa » Html Button Properties