HTML Buttons: Complete Guide to the <button> Element
Buttons are one of the most important interactive elements in modern websites. They allow users to perform actions such as submitting forms, opening menus, starting a search, showing hidden content, playing media, confirming an action, or triggering JavaScript functionality.
HTML provides the <button> element specifically for creating interactive buttons. It is simple to use, highly customizable with CSS, and can be connected to JavaScript when a website needs more advanced behavior.
This guide explains HTML buttons in detail, including syntax, button types, attributes, forms, accessibility, styling, JavaScript usage, common mistakes, best practices, and practical examples.
What Is an HTML Button?
An HTML button is an interactive element created with the <button> tag.
The basic syntax is:
<button>Click Me</button>
The text between the opening and closing <button> tags becomes the visible content of the button.
For example:
<button>Submit</button>
A browser will display a clickable button containing the word “Submit”.
Unlike plain text or a <div>, a real HTML <button> is designed to be interactive. It can normally be reached with the keyboard, activated with the keyboard, and understood by assistive technologies when used correctly.
Basic HTML Button Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Button Example</title>
</head>
<body>
<button>Click Me</button>
</body>
</html>
This creates a simple button on the page.
By itself, the button does not necessarily perform a custom action. JavaScript, a form, or another appropriate mechanism can give the button a specific purpose.
The <button> Element
The <button> element is a semantic HTML element used for user-triggered actions.
Its basic structure is:
<button type="button">
Button Text
</button>
The type attribute is especially important when the button is placed inside a form.
For example:
<button type="submit">Submit Form</button>
<button type="reset">Reset Form</button>
<button type="button">Click Me</button>
Types of HTML Buttons
There are three main values of the type attribute for buttons:
buttonsubmitreset
1. type="button"
A button with type="button" is a general-purpose button.
<button type="button">Click Me</button>
It does not submit or reset a form by default.
This is usually the best choice for buttons that perform JavaScript-based actions but are not intended to submit a form.
Example:
<button type="button" onclick="showMessage()">
Show Message
</button>
<script>
function showMessage() {
alert("Hello!");
}
</script>
2. type="submit"
A submit button is used to submit a form.
<form>
<input type="text" name="username">
<button type="submit">Submit</button>
</form>
When the user activates the button, the browser attempts to submit the associated form.
If a button is inside a <form> and no type is specified, browsers generally treat it as a submit button. Therefore, explicitly setting type="button" is a good practice for non-submit buttons inside forms.
3. type="reset"
A reset button restores form controls to their initial values.
<form>
<input type="text" name="name">
<input type="email" name="email">
<button type="reset">Reset</button>
</form>
Reset buttons should be used carefully. Users may accidentally lose information they have entered.
Why the type Attribute Matters
Consider this example:
<form>
<input type="text" name="name">
<button>Save</button>
<button onclick="doSomething()">Another Action</button>
</form>
The second button may also act as a submit button because the default button type in a form is submit.
A safer version is:
<form>
<input type="text" name="name">
<button type="submit">Save</button>
<button type="button" onclick="doSomething()">Another Action</button>
</form>
This makes the intended behavior clear.
HTML Button Syntax
A typical button can be written as:
<button
type="button"
id="myButton"
class="primary-button"
title="Click this button">
Click Me
</button>
The button can contain text, images, icons, or other suitable phrasing content.
For example:
<button type="button">
Save
</button>
Or:
<button type="button">
💾 Save
</button>
Button Content
A major advantage of <button> over some other controls is that it can contain richer content.
For example:
<button type="button">
<strong>Save</strong>
</button>
It can also contain an image:
<button type="button">
<img src="save-icon.png" alt="">
Save
</button>
For icons, decorative images should generally use an empty alt attribute so screen readers do not unnecessarily announce the image.
Important HTML Button Attributes
The <button> element supports many global HTML attributes and several attributes that are particularly useful for buttons.
type
Defines the button’s behavior.
<button type="button">Normal Button</button>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
id
Provides a unique identifier.
<button id="saveButton" type="button">Save</button>
JavaScript can use the ID to find the button:
const button = document.getElementById("saveButton");
class
Assigns one or more CSS classes.
<button class="primary-button" type="button">
Save
</button>
CSS can then style the button.
name
Provides a name for the button, especially useful when submitting forms.
<button type="submit" name="action" value="save">
Save
</button>
value
Specifies the button’s value.
<button type="submit" name="action" value="save">
Save
</button>
The submitted value can help a server determine which submit button was activated.
disabled
Disables the button.
<button type="button" disabled>
Unavailable
</button>
A disabled button generally cannot be activated by the user.
JavaScript can enable it later:
document.querySelector("button").disabled = false;
form
Associates a button with a form by its ID.
<form id="myForm">
<input type="text" name="username">
</form>
<button type="submit" form="myForm">
Submit
</button>
The button can therefore be outside the <form> element while still being associated with it.
formaction
Specifies a URL where the form data should be submitted for a submit button.
<button
type="submit"
formaction="/save">
Save
</button>
This can be useful when different submit buttons perform different actions.
formenctype
Specifies how form data should be encoded when submitted.
<button
type="submit"
formenctype="multipart/form-data">
Upload
</button>
It is mainly relevant when submitting forms containing file uploads.
formmethod
Specifies the HTTP method used to submit the form.
<button type="submit" formmethod="post">
Submit
</button>
Common values include:
get
post
dialog
formnovalidate
Prevents normal browser form validation when that particular submit button is used.
<button type="submit" formnovalidate>
Submit Without Validation
</button>
This can be useful for special actions, such as saving a partially completed form.
formtarget
Specifies where the response from the form submission should be displayed.
<button type="submit" formtarget="_blank">
Submit
</button>
popovertarget
Modern HTML also supports button-based interaction with the Popover API.
Example:
<button type="button" popovertarget="info">
Show Information
</button>
<div id="info" popover>
Additional information goes here.
</div>
This allows a button to control a popover without requiring custom JavaScript for the basic show/hide operation.
popovertargetaction
This can specify the action performed on a popover.
For example:
<button
type="button"
popovertarget="menu"
popovertargetaction="toggle">
Toggle Menu
</button>
<div id="menu" popover>
Menu content
</div>
HTML Button vs. <input type="button">
HTML provides more than one way to create button-like controls.
For example:
<button type="button">Click Me</button>
and:
<input type="button" value="Click Me">
Both can create buttons, but they are not identical.
The <button> element is generally more flexible because it can contain content such as text, images, and suitable inline elements.
For example:
<button type="button">
<span>⭐</span>
Favorite
</button>
An <input type="button"> uses its value as its displayed text.
For modern interfaces, <button> is usually the more flexible choice.
HTML Button vs. Link
A common mistake is using a button when a link should be used, or using a link when a button should be used.
Use a <button> when the user is performing an action.
Examples:
- Open a menu
- Submit a form
- Start a process
- Delete an item
- Show or hide content
- Play or pause media
- Add an item to a list
Use an <a> element when the user is navigating to another URL or resource.
Example:
<a href="/about.html">About Us</a>
A navigation link should not normally be replaced with:
<button onclick="location.href='/about.html'">
About Us
</button>
The link is more semantic and provides the browser with navigation information.
Button and Forms
Buttons are frequently used inside forms.
Example:
<form action="/register" method="post">
<label for="name">Name:</label>
<input id="name" name="name" type="text">
<button type="submit">Register</button>
</form>
The submit button tells the browser to submit the form.
A form can contain multiple buttons:
<form>
<input type="text" name="name">
<button type="submit" name="action" value="save">
Save
</button>
<button type="submit" name="action" value="preview">
Preview
</button>
</form>
The server can determine which action was selected based on the submitted button’s name and value.
Button and JavaScript
JavaScript can add interactive behavior to buttons.
A basic example is:
<button type="button" id="helloButton">
Click Me
</button>
<script>
const button = document.getElementById("helloButton");
button.addEventListener("click", function () {
alert("Hello, world!");
});
</script>
This approach is generally preferable to placing large amounts of JavaScript directly inside HTML attributes.
Inline onclick
A button can also use the onclick attribute:
<button type="button" onclick="alert('Hello!')">
Click Me
</button>
This works, but separating HTML structure from JavaScript behavior is often easier to maintain.
A cleaner approach is:
<button type="button" id="helloButton">
Click Me
</button>
<script>
document.getElementById("helloButton").addEventListener("click", () => {
alert("Hello!");
});
</script>
Changing Button Text with JavaScript
<button type="button" id="myButton">
Click Me
</button>
<script>
const button = document.getElementById("myButton");
button.addEventListener("click", () => {
button.textContent = "Clicked!";
});
</script>
Disabling a Button with JavaScript
<button type="button" id="submitButton">
Submit
</button>
<script>
const button = document.getElementById("submitButton");
button.disabled = true;
</script>
A button can later be enabled:
button.disabled = false;
Creating a Toggle Button
Buttons can control a state, such as opening or closing a menu.
<button
type="button"
id="menuButton"
aria-expanded="false">
Menu
</button>
<nav id="menu" hidden>
<a href="/home">Home</a>
<a href="/about">About</a>
</nav>
<script>
const button = document.getElementById("menuButton");
const menu = document.getElementById("menu");
button.addEventListener("click", () => {
const isOpen = button.getAttribute("aria-expanded") === "true";
button.setAttribute("aria-expanded", String(!isOpen));
menu.hidden = isOpen;
});
</script>
Here, aria-expanded communicates the current state to assistive technologies.
Button Accessibility
Accessibility is an important part of button design.
A properly implemented native <button> already provides many accessibility benefits. It can usually be focused and activated using standard keyboard controls.
Use a Real Button
Avoid creating fake buttons with a <div> whenever a real button is appropriate.
Less suitable:
<div onclick="saveData()">Save</div>
Better:
<button type="button" onclick="saveData()">
Save
</button>
A native button provides built-in semantics and interaction behavior.
Use Clear Button Text
Button labels should clearly communicate the action.
Good examples:
<button type="button">Save Changes</button>
<button type="button">Delete Account</button>
<button type="button">Add to Cart</button>
Less helpful labels include:
<button type="button">Click Here</button>
<button type="button">Go</button>
A user should ideally understand what will happen before activating the button.
Icon-Only Buttons
Sometimes a button contains only an icon.
For example:
<button type="button" aria-label="Close">
×
</button>
The aria-label gives the button an accessible name.
Another example:
<button type="button" aria-label="Search">
🔍
</button>
An icon alone may not communicate its purpose clearly to every user.
aria-label Should Not Replace Visible Text Unnecessarily
If a button already has clear visible text, adding an identical aria-label is generally unnecessary.
For example:
<button type="button">
Search
</button>
is usually sufficient.
For an icon-only button:
<button type="button" aria-label="Search">
🔍
</button>
is more appropriate.
Keyboard Accessibility
Native HTML buttons are keyboard accessible.
Users can normally:
- Move focus to the button using the Tab key.
- Activate a focused button with standard keyboard controls.
- Navigate through interactive elements without a mouse.
This is another reason to prefer <button> over manually creating clickable <div> or <span> elements.
Button Focus
Do not remove the browser’s focus indicator without providing a suitable alternative.
Avoid:
button:focus {
outline: none;
}
Removing focus indicators can make keyboard navigation difficult.
If you customize focus styling, make sure the focused state remains obvious.
For example:
button:focus-visible {
outline: 3px solid currentColor;
outline-offset: 2px;
}
Styling HTML Buttons with CSS
HTML creates the structure, while CSS controls appearance.
Example:
<button class="primary-button" type="button">
Save Changes
</button>
.primary-button {
padding: 10px 18px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
}
You can customize:
- Color
- Background
- Border
- Border radius
- Font
- Size
- Padding
- Width
- Height
- Shadows
- Transitions
- Hover effects
- Focus styles
- Disabled appearance
Hover Effects
button:hover {
opacity: 0.85;
}
Hover effects can improve visual feedback for mouse users, but important information should not depend only on hover because touch-screen and keyboard users may not experience it.
Active State
CSS can style a button while it is being activated:
button:active {
transform: scale(0.98);
}
Disabled Button Styling
button:disabled {
cursor: not-allowed;
opacity: 0.6;
}
Disabled controls should look unavailable while still maintaining sufficient visual clarity.
Button Width
A button can have a fixed width:
button {
width: 150px;
}
Or it can fill its container:
button {
width: 100%;
}
For responsive designs, avoid unnecessarily forcing large fixed widths.
Button as a Flex Container
A button can be styled using Flexbox.
.button {
display: inline-flex;
align-items: center;
gap: 8px;
}
HTML:
<button class="button" type="button">
<span>💾</span>
Save
</button>
This is useful for buttons containing icons and text.
Button with an Icon
<button type="button" class="download-button">
<span aria-hidden="true">⬇</span>
Download
</button>
aria-hidden="true" can be used for a purely decorative icon when the visible text already identifies the action.
Button States
A well-designed button can have different visual states.
Common states include:
- Normal
- Hover
- Focus
- Active
- Disabled
- Loading
- Selected or pressed
Example:
.button:hover {
opacity: 0.9;
}
.button:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}
.button:active {
transform: translateY(1px);
}
.button:disabled {
opacity: 0.5;
}
Toggle and Pressed Buttons
Some buttons represent an on/off or selected/unselected state.
For example:
<button
type="button"
aria-pressed="false">
Favorite
</button>
JavaScript can update the state:
const button = document.querySelector("button");
button.addEventListener("click", () => {
const pressed = button.getAttribute("aria-pressed") === "true";
button.setAttribute("aria-pressed", String(!pressed));
});
aria-pressed is useful when a button behaves as a toggle.
Loading Buttons
A button may temporarily display a loading state while an operation is in progress.
Example:
<button type="button" id="saveButton">
Save
</button>
JavaScript:
const button = document.getElementById("saveButton");
button.addEventListener("click", async () => {
button.disabled = true;
button.textContent = "Saving...";
// Perform an operation here.
button.disabled = false;
button.textContent = "Save";
});
In a real application, the button should be re-enabled after the operation succeeds or fails.
Preventing Double Submissions
A submit button can be disabled after the form is submitted to reduce accidental repeated submissions.
<form id="myForm">
<input type="text" name="name" required>
<button type="submit">Submit</button>
</form>
<script>
const form = document.getElementById("myForm");
form.addEventListener("submit", () => {
const button = form.querySelector("button[type='submit']");
button.disabled = true;
button.textContent = "Submitting...";
});
</script>
Server-side protection should still be used when duplicate submissions could cause serious problems.
Button Events
Buttons can respond to various browser events.
Common events include:
clickmousedownmouseupkeydownkeyupfocusblur
The click event is commonly used for button actions:
button.addEventListener("click", () => {
console.log("Button clicked");
});
Using the native button element also makes keyboard activation behavior much easier than building a custom control from scratch.
Form Validation and Buttons
HTML forms support built-in validation.
Example:
<form>
<label for="email">Email:</label>
<input
id="email"
name="email"
type="email"
required>
<button type="submit">
Submit
</button>
</form>
The browser can prevent submission when required constraints are not satisfied.
A special submit button can bypass browser constraint validation with:
<button type="submit" formnovalidate>
Save Draft
</button>
Multiple Submit Buttons
A form can contain multiple submit buttons.
<form action="/process" method="post">
<input type="text" name="title">
<button type="submit" name="action" value="save">
Save
</button>
<button type="submit" name="action" value="publish">
Publish
</button>
</form>
The server can inspect the action value to determine which operation the user requested.
Button Outside a Form
A button does not have to be inside a form.
<button type="button">
Open Menu
</button>
It can also be associated with a form using the form attribute:
<form id="contactForm">
<input name="email" type="email">
</form>
<button type="submit" form="contactForm">
Submit
</button>
Button and the disabled Attribute
The disabled attribute is a Boolean attribute.
This is valid:
<button disabled>
Disabled
</button>
It is not necessary to write:
<button disabled="true">
A Boolean HTML attribute is enabled by its presence.
For example:
<button disabled>
Submit
</button>
The button can be enabled dynamically:
button.disabled = false;
readonly Does Not Apply to Buttons
Unlike text inputs, buttons do not use a readonly attribute to make their content uneditable.
A button is either interactive or disabled, depending on its state and implementation.
Button Name and Value
Buttons can contribute data during form submission.
Example:
<form method="post">
<input name="username" type="text">
<button type="submit" name="action" value="save">
Save
</button>
</form>
When this button is used to submit the form, its name and value can be included in the submitted form data.
Reset Buttons: Use With Care
The reset button has a specific purpose:
<button type="reset">
Reset Form
</button>
It restores controls to their initial values.
Because users can lose entered data, reset buttons should not be added unless the behavior is genuinely useful.
HTML Button Best Practices
1. Use the Correct Element
Use <button> for actions and <a> for navigation.
2. Always Set type in Forms
For clarity, use:
<button type="submit">Submit</button>
and:
<button type="button">Open</button>
rather than relying on the default behavior.
3. Use Descriptive Labels
Prefer:
<button type="button">Delete Account</button>
over:
<button type="button">Click Here</button>
4. Keep Buttons Keyboard Accessible
Use native buttons whenever possible.
5. Do Not Remove Focus Indicators Without Replacing Them
Keyboard users need to know which element currently has focus.
6. Make Buttons Large Enough to Use
Buttons should have enough space around their text and controls. This is especially important on touch-screen devices.
7. Provide Clear Feedback
If an action takes time, consider showing a meaningful loading state.
8. Avoid Unnecessary Reset Buttons
A reset button can accidentally remove user input.
9. Do Not Use Buttons for Simple Navigation
For navigation, use links.
10. Keep Button Text Short
A button should communicate its action quickly.
Common HTML Button Mistakes
Mistake 1: Forgetting type
<form>
<button onclick="openMenu()">Menu</button>
</form>
The button can submit the form unexpectedly.
Better:
<form>
<button type="button" onclick="openMenu()">Menu</button>
</form>
Mistake 2: Using a <div> as a Button
Avoid:
<div onclick="submitForm()">Submit</div>
Prefer:
<button type="button" onclick="submitForm()">
Submit
</button>
Mistake 3: Using a Link for an Action
Avoid turning a link into a fake button when the operation does not represent navigation.
Mistake 4: Removing Focus Outlines
button {
outline: none;
}
This can make keyboard navigation harder.
Mistake 5: Using Only an Icon Without an Accessible Name
Avoid:
<button type="button">×</button>
for an icon-only control when its purpose is not otherwise clear.
Better:
<button type="button" aria-label="Close">
×
</button>
Mistake 6: Using JavaScript When Native HTML Can Do the Job
Modern HTML provides useful native functionality. Use native HTML semantics where they fit before adding unnecessary JavaScript.
Complete HTML Button Example
Here is a small example combining HTML, CSS, JavaScript, accessibility, and button states:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Button Example</title>
<style>
.button {
padding: 10px 18px;
border: 0;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
}
.button:hover {
opacity: 0.9;
}
.button:focus-visible {
outline: 3px solid currentColor;
outline-offset: 2px;
}
.button:disabled {
cursor: not-allowed;
opacity: 0.5;
}
</style>
</head>
<body>
<button
type="button"
class="button"
id="messageButton">
Show Message
</button>
<script>
const button = document.getElementById("messageButton");
button.addEventListener("click", () => {
button.textContent = "Message Shown";
});
</script>
</body>
</html>
Semantic Meaning of <button>
HTML is not only about appearance. It also communicates meaning.
When you write:
<button type="button">Save</button>
you tell the browser that this element represents a button.
That semantic information can be used by:
- Browsers
- Screen readers
- Keyboard users
- Search and accessibility technologies
- JavaScript
- Automated testing tools
This is one reason semantic HTML is important.
Buttons and SEO
Buttons generally perform actions rather than provide navigation.
Search engines do not treat a button as a normal navigational link. Therefore, if you want users and search engines to understand that a destination is a webpage, use a proper link:
<a href="/contact">Contact Us</a>
Use:
<button type="button">Open Search</button>
when the control performs an action such as opening a search interface.
Good semantic HTML improves the structure and usability of a website, even when a particular element does not directly provide an SEO ranking benefit.
Buttons in Responsive Web Design
Buttons should work well on desktops, tablets, and mobile devices.
A responsive button might use:
button {
min-height: 44px;
padding: 10px 16px;
}
The exact dimensions should depend on the design and context.
Avoid making touch targets so small that users have difficulty activating them.
Button Design Principles
A good button should generally have:
- A clear purpose
- A readable label
- Good contrast
- A visible focus state
- A recognizable interactive appearance
- Appropriate spacing
- A clear disabled state when necessary
- Consistent styling
- Appropriate feedback after activation
Visual design should support meaning rather than hide it.
Button Security Considerations
HTML buttons themselves are not inherently a security risk. However, actions triggered by buttons can have security consequences.
For example, a button that deletes an account should not rely only on front-end JavaScript for authorization.
Important operations should be validated and authorized on the server.
For sensitive actions, consider:
- Server-side authorization
- CSRF protection where applicable
- Input validation
- Confirmation for destructive operations
- Safe handling of submitted data
- Appropriate authentication
Disabling a button in HTML does not provide security. A user can modify client-side HTML, so security controls must exist on the server when necessary.
HTML Button and Accessibility APIs
Native buttons expose their role and state to accessibility technologies.
For example:
<button type="button">
Save
</button>
communicates that the element is a button.
For stateful controls, attributes such as:
aria-expanded="true"
or:
aria-pressed="true"
can communicate additional state when appropriate.
ARIA should enhance correct HTML rather than replace native semantics unnecessarily.
Button vs. <input type="submit">
These are both valid form controls:
<input type="submit" value="Submit">
and:
<button type="submit">Submit</button>
The <button> version is generally more flexible because it can contain richer content and can be styled and structured more freely.
For example:
<button type="submit">
<span aria-hidden="true">✓</span>
Submit Application
</button>
Can a Button Contain an Image?
Yes, a <button> can contain an image.
<button type="button">
<img src="download.png" alt="">
Download
</button>
The image should have meaningful alternative text if it conveys information not already provided by the button text. If it is decorative, an empty alt attribute is generally appropriate.
Can a Button Contain a Link?
Placing an interactive link inside a button is generally inappropriate because it creates nested interactive controls.
Avoid structures such as:
<button type="button">
<a href="/page">Open Page</a>
</button>
Choose the correct interactive element instead.
Can a Button Be Styled Like a Link?
Yes, CSS can make a button visually resemble a link.
However, appearance should not change the underlying semantic purpose.
If it navigates, use a link. If it performs an action, use a button.
Can a Link Be Styled Like a Button?
Yes.
For example:
<a href="/signup" class="button">
Sign Up
</a>
This is still a link semantically, even though CSS can make it look like a button.
That can be appropriate when the destination is another page or URL.
HTML Button Accessibility Checklist
Before publishing a website, check whether:
- The control uses a real
<button>when it performs an action. - The button has a clear accessible name.
- Its purpose is understandable.
- It can be operated with a keyboard.
- Focus is visible.
- Disabled states are communicated appropriately.
- Icon-only buttons have accessible names.
- Toggle buttons communicate their state.
- Form buttons have the correct
type. - Destructive actions have suitable safeguards.
- Touch users can comfortably activate the control.
Frequently Asked Questions About HTML Buttons
What is the HTML tag for a button?
The HTML tag is:
<button></button>
For example:
<button type="button">Click Me</button>
What does the <button> tag do?
It creates an interactive button that can perform actions, submit forms, reset forms, or control other interface features.
What are the three button types in HTML?
The three main button types are:
button
submit
reset
What is the default type of a button inside a form?
When a button associated with a form has no type attribute, its default behavior is generally submit.
For clarity, explicitly specify the intended type.
How do I make a button clickable?
A native <button> is already interactive:
<button type="button">Click Me</button>
You can attach JavaScript to perform a custom action.
How do I disable an HTML button?
Use:
<button type="button" disabled>
Disabled
</button>
How do I submit a form with a button?
Use:
<button type="submit">
Submit
</button>
inside the form, or associate the button with a form using the form attribute.
Can HTML buttons contain icons?
Yes. A <button> can contain suitable text, icons, and other appropriate content.
Should I use <button> or <a>?
Use <button> for actions and <a> for navigation.
Are HTML buttons keyboard accessible?
Native buttons are designed for keyboard interaction and are preferable to manually created clickable elements.
How do I create an icon-only button?
Use a meaningful accessible name:
<button type="button" aria-label="Close">
×
</button>
How do I create a reset button?
Use:
<button type="reset">Reset</button>
How do I create a submit button?
Use:
<button type="submit">Submit</button>
Final Thoughts
The HTML <button> element may look simple, but it is a powerful and important part of web development. It provides native interaction, semantic meaning, keyboard support, form functionality, and compatibility with accessibility technologies.
The most important rule is to use buttons for actions and links for navigation. Inside forms, explicitly define the button’s type so that its behavior is clear. Use descriptive labels, preserve keyboard accessibility, provide visible focus states, and use attributes such as aria-expanded or aria-pressed when a button represents a changing state.
A strong HTML button implementation combines three things: correct HTML semantics, thoughtful accessibility, and appropriate CSS or JavaScript behavior. When these are used together, buttons become reliable, understandable, responsive, and easy for people to use across different devices and assistive technologies.