References

Beginner-friendly references for web development, with live, editable examples.

The HTML formnovalidate attribute

Attribute All modern browsers
In short

A submit button with formnovalidate sends its form unchecked, which lets a Save draft button store unfinished work. Any other submit button still runs every check, unless the form has novalidate. Inputs of type submit or image accept the attribute too.

Overview

The HTML formnovalidate attribute lets one submit button send its form without validation. It is useful for save buttons, which let people store unfinished work while the button that completes the form still checks every field.

The validator.nu checker rejects formnovalidate on a type="button" or type="reset" <button>, where it has no effect anyway. The same goes for an <input> of type button.

Pressing a Save draft button with name="intent" and value="draft" adds intent=draft to the submission, and a Publish button's value stays out. That one entry lets your server tell a draft from a finished post.

The attribute covers a single button. To skip validation however the form is submitted, put novalidate on the form instead.

Syntax

<form action="/posts" method="post">
  <label for="title">Title</label>
  <input id="title" name="title" required>
  <button name="intent" value="publish">Publish</button>
  <button name="intent" value="draft" formnovalidate>Save draft</button>
</form>

Values

Value
On a submit button, presence alone skips validation for that button.

Example

Live example
<form id="post">
  <label for="title">Title</label>
  <input id="title" name="title" required><br>
  <label for="body">Post</label>
  <textarea id="body" name="body" rows="2" cols="24" required></textarea>
  <p>
    <button name="intent" value="publish">Publish</button>
    <button name="intent" value="draft" formnovalidate>Save draft</button>
  </p>
</form>
<p id="out" role="status" style="overflow-wrap:anywhere"></p>
<p>Leave the fields empty and press each button.</p>
<script>
const form = document.getElementById('post');
const out = document.getElementById('out');
form.addEventListener('invalid', function () {
  out.textContent = 'Publish was blocked because a required field is empty.';
}, true);
form.addEventListener('submit', function (e) {
  e.preventDefault();
  const data = new URLSearchParams(new FormData(form, e.submitter));
  out.textContent = e.submitter.textContent + ' would send ' + data;
});
</script>

Best practices

  • Check what Enter does once a form has a formnovalidate button. If Save draft comes first in the source, Enter skips validation, so keep Publish ahead of it.
  • Have the server relax its required-field checks only when the submitted intent says draft. A formnovalidate button sends empty text fields as empty strings, such as title=, and leaves out unticked checkboxes.
  • Send drafts to their own URL by adding formaction to the same button, such as formaction="/drafts". The Publish button then keeps the form's action.
  • For an autosave timer, use form.requestSubmit(draftButton). It fires your submit handler and skips validation, the same as a click on Save draft.

Frequently asked questions

Why add formnovalidate to a submit button?
The formnovalidate attribute lets an extra submit button, such as Save draft, skip validation. Required fields and patterns are still checked when a different submit button sends the form.
Which checks does formnovalidate skip?
A formnovalidate submission skips every constraint, such as required, pattern, minlength and the email type check. Each field still sends its current value, which for a number field showing 1e is an empty string.
Does formnovalidate change what an image button sends?
No, formnovalidate skips validation but adds nothing to what an image button sends. An image button that submits a form adds the click position as x and y entries, or go.x and go.y when its name is go.
Is formnovalidate a good fit for a Cancel button?
Yes, a Cancel submit button with formnovalidate lets people leave the form without tripping over empty required fields. The server still gets the request, though, and should check which button sent it.
Do fields stay invalid after a formnovalidate submission?
Yes, formnovalidate only skips the check for that submission, and the fields keep their invalid state. A later press of a button without formnovalidate still runs every check and blocks the form while a field is invalid.