How to Make a Button in HTML
To make a button in HTML, use the <button> element: <button type="button">Click me</button>. Style it with CSS, run JavaScript when it is clicked, or set type="submit" to send a form. If the button should take people to another page, use a link styled as a button instead. Every example below is live.
Last updated: October 4, 2026
Quick answer
Step 1: Add a button with the <button> tag
The <button> element creates a real, clickable button. Whatever you put between the opening and closing tags becomes the label. That can be plain text, or other inline content like an icon or bold text.
- Type
<button>, then the label, then</button>. - Add
type="button"so the browser knows it’s a plain button and not a form submit button. - Open the page. The browser already makes it focusable with the Tab key and clickable with Enter or Space.
Those default buttons look different in every browser and operating system. That’s why almost every site restyles them with CSS, which is the next step.
Step 2: Choose the right type attribute
The type attribute decides what the button does:
type="button": does nothing by itself. Use it for buttons that run JavaScript.type="submit": sends the form it sits in. This is the default when a button is inside a<form>and has no type.type="reset": clears every field in the form back to its starting value. Users press it by accident, so it’s rarely a good idea.
Because submit is the default, a button with no type inside a form will submit (and reload) the page when clicked. Always write the type, even when it seems obvious.
Step 3: Style the button with CSS
A good button style changes four things: the colors, the padding (space around the label), the border radius (rounded corners) and the cursor. Then it adds states, so people can see when the button is hovered, pressed or focused with the keyboard.
- Give the button a class, such as
class="btn". - Set
background,color,padding,border: noneandborder-radius. - Add
cursor: pointerso the mouse shows a hand. - Add
:hover,:activeand:focus-visiblerules for the different states.
Try changing the background color or the border radius in the example.
Keep the :focus-visible outline. People who use a keyboard rely on it to see which button is selected, and removing it with outline: none is one of the most common accessibility mistakes.
Step 4: Make a link that looks like a button
Buttons do things (open a menu, save, submit). Links go places. If clicking should take someone to another page, use an <a href> and give it the same CSS class as your buttons. Search engines follow links, people can open them in a new tab, and screen readers announce them correctly.
- Write a normal link:
<a href="/editor/">Open the editor</a>. - Add your button class and
display: inline-blockso padding works on it. - Remove the underline with
text-decoration: none.
Avoid wrapping a <button> inside an <a> (or the other way round). Nesting interactive elements is invalid HTML and confuses keyboards and screen readers.
Step 5: Run JavaScript when the button is clicked
To make a button do something on the page, listen for its click event. Give the button an id, find it with document.getElementById, and attach a function with addEventListener. The example below counts clicks.
You’ll also see onclick="..." written straight into the HTML. It works, but keeping JavaScript in a <script> block (or a separate file) is easier to read and maintain once a page has more than one button.
Disabled buttons and buttons with icons
Add the disabled attribute to switch a button off. It turns grey, can’t be clicked or focused, and is skipped when a form is submitted. Style it with the :disabled selector. For icons, put an inline SVG or an emoji next to the text, and if the button has only an icon, give it an aria-label so screen readers can announce what it does.
Button size and spacing on phones
On a touch screen, fingers are far less precise than a mouse pointer. Make tap targets at least 44 × 44 pixels: padding: 12px 20px on a 16-pixel label is usually enough. Leave at least 8 pixels between neighbouring buttons with gap or margin, so people don’t hit the wrong one. For the main action on a small screen, such as “Sign up” or “Checkout”, a full-width button is easiest to tap. Add it in a media query, so it only applies on narrow screens: @media (max-width: 600px) { .btn-main { width: 100%; } }.
<button> vs <input> vs <a>: which to use
| Element | Can contain | Use it for |
|---|---|---|
<button> | Text, icons, other inline HTML | Actions: run JavaScript, submit or reset a form. The modern default |
<input type="button"> | Plain text only (the value attribute) | Older code. Works, but can’t hold icons or formatting |
<input type="submit"> | Plain text only | Submitting a form, in older code |
<a href> styled as a button | Text, icons, inline HTML | Going to another page or section |
Common mistakes when making buttons
- Leaving out
typeinside a form. The button defaults to submit and reloads the page. Writetype="button"for JavaScript buttons. - Using a
<div>as a button. A clickable div can’t be reached with the Tab key or pressed with Enter. Use a real<button>. - Using a button to change pages. Use a link for navigation, so it can be opened in a new tab and followed by search engines.
- Removing the focus outline. Restyle it with
:focus-visibleinstead of deleting it. - Icon-only buttons with no label. Add
aria-labelso screen reader users know what the button does. - Buttons that are too small. Aim for at least 44 × 44 pixels on touch screens.