Format Code Now
/
Web & markupHTML Button Generator Next: HTML Citation Generator ›

HTML Button Generator

WM-27

Type the label, choose button, submit or reset, and copy a button element. The type is always written, because a button left without one acts as submit inside a form.

Runs in your browser. Nothing is uploaded.

Button text (optional lines: name:, value:, form:, formaction:, formmethod:, disabled:, autofocus:)

HTML

How to use it

  1. Type the button text. Add name:, value:, form:, formaction:, formmethod:, disabled: or autofocus: lines as needed.
  2. Choose the type: button, submit or reset.
  3. Copy the generated button element.
  4. Add your own click handler or put it inside a form.

Why the type attribute matters

A button element placed inside a form submits that form when it has no type, or an invalid one. That surprises people who add a button to open a menu and find the page reloading. Setting type="button" gives a button that does nothing until you attach script. type="submit" sends the form and type="reset" puts the controls back to their starting values. This tool always writes the type for that reason.

Form attributes on one button

A submit button can override its form for a single click. formaction sends the data to a different address, formmethod switches between get, post and dialog, formtarget chooses where the response opens, and formnovalidate skips the browser validation. The name and value pair is sent with the form, so a server can tell which of several buttons was pressed. These lines are copied as you give them, apart from a check that formmethod is valid.

Error messages and what to do

MessageWhat it meansFix
Type the text for the element above the key: value lines.The input box held only key: value lines, so there is no button text.Type the label on its own line above the other lines.
"formmethod:" must be get, post or dialog.The formmethod line had another value.Use get, post or dialog.

Questions people ask

What is the default type of an HTML button?

Submit. When a button has no type attribute, or one the browser does not recognise, it behaves as a submit button and sends the form it sits in. Writing type="button" explicitly avoids accidental submits.

How do I make a button that does not submit a form?

Give it type="button". It then has no built-in action, and you add behavior with a click handler. Inside a form, forgetting this is the most common reason a page reloads when a button is pressed.

What is the difference between button and input type=button?

A button element has start and end tags and can hold other inline markup such as an icon and text. An input of type button is a single tag and its label comes from the value attribute, so it can only be plain text.

What does a disabled button do?

A disabled button cannot be clicked or focused with the keyboard, and it is left out of form submission. Add a disabled: true line to write the bare disabled attribute. Do not rely on it for security, since anyone can edit the markup.

How do I send which button was pressed?

Give each submit button a name and a value. Only the button that was used to submit is included in the data, so the server can read the name and value and branch on it.

About this tool

Writes one <button> with the type you pick. The type is always written, because a button inside a form defaults to submit when type is left out. Boolean lines such as disabled: true add the bare attribute; disabled: false adds nothing. formaction and formmethod only make sense for a submit button; they are copied as given. Button text is escaped as plain text, so it cannot hold child elements such as an icon. A javascript: address in formaction is refused. The tool writes markup only: there is no click handler and no styling. Optional lines: id:, class:, title:, lang:, data-* and aria-*.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.