HTML & CSS Interview Question #43

What do novalidate and formnovalidate do?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Mid-Level Intermediate

Quick Interview Answer

The novalidate attribute on a form disables the browser's normal constraint validation when that form is submitted. formnovalidate can disable validation for a particular submit button.

Detailed Explanation

The novalidate attribute on a form disables the browser's normal constraint validation when that form is submitted. formnovalidate can disable validation for a particular submit button.

These attributes can be useful for workflows such as saving a draft before all required fields are complete. They do not affect server-side validation, which should still validate data according to the selected operation.

Code Example

<form action="/article/save" method="post">
    <input name="title" required>

    <button type="submit">
        Publish
    </button>

    <button type="submit"
            name="action"
            value="draft"
            formnovalidate>
        Save Draft
    </button>
</form>