Lesson

HTML Input Form Attributes

10 min reading
Free Course

HTML Input Form Attributes: Per-Button Overrides and External Inputs

HTML input form attributes let a single button or field behave differently from the form that contains it. With attributes such as formaction, formmethod, formnovalidate, formtarget, and form, you can give one form several actions, or connect a field that sits outside the <form> tags. They are a clean fix for a common interface problem: a form that needs both a "Save Draft" button and a "Publish Now" button.

What Are HTML Input Form Attributes?

Normally, a <form> element decides where its data goes(action), how it is sent (method), whether it is validated(novalidate), and where the response appears (target). Every submit button inside the form follows those rules.

The form* attributes change that for one control only. They are written on a submit button (or an <input type="submit"> or <input type="image">) and take priority over the matching setting on the parent form, but only when that specific button is used to submit. The form's own settings stay as they are for every other button.

The form attribute is slightly different. It doesn't override anything. It attaches a control to a form it isn't physically inside.

Overriding Parent Form Behavior per Button

When a user clicks a specific submit button, attributes on that button take precedence over the enclosing form tag:

  • formaction: Sends the form to an alternate URL (for example, /posts/draft vs /posts/publish).

  • formmethod: Overrides the HTTP method (get or post) for that button only.

  • formnovalidate: Skips HTML5 required/pattern validation on that button—ideal for "Save Draft" or "Cancel" buttons.

  • formtarget: Opens the response of that specific submission in a new tab (_blank) for previews.

  • form="form-id": Connects an input, select, textarea, or button located anywhere else on the page to a specific form by matching its id.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTML Input Form Attributes Demo</title>
</head>
<body>
    <form id="article-form" action="/articles/publish" method="post">
        <label for="post-title">Article Title</label>
        <input id="post-title" name="title" type="text" required>

        <div style="margin-top: 12px;">
            <button type="submit">Publish Now</button>
            <button type="submit" formaction="/articles/draft" formnovalidate>Save Draft</button>
        </div>
    </form>

    <!-- Linked to #article-form even though outside the form tag -->
    <div style="margin-top: 12px;">
        <label for="post-tag">Category Tag</label>
        <input id="post-tag" name="tag" type="text" form="article-form">
    </div>
</body>
</html>

Here is what happens in each case:

  • Publish Now has no overrides. It posts to/articles/publish, and the browser blocks the submission if the title is empty.

  • Save Draft posts to /articles/draft and skips validation so that an empty title won't stop it.

  • Category Tag sits outside the <form>, yet its value (tag) is sent along with the title, because form="article-form" connects it.

How to Check That It Works

You don't need a backend to confirm the behavior. Try these steps:

  1. Open the page in a browser and leave the title empty. Click Publish Now. The browser should show a "Please fill out this field" message and not submit.

  2. Click Save Draft with the title still empty. The form should submit to /articles/draft.

  3. Open DevTools, switch to the Network tab, and submit again. Check the request URL and the form data to confirm the path is right and that both title and tag are included.

  4. If you have no server yet, point the actions at a test endpoint or look at the request in the Network panel, even if it returns a 404. The request details still show what was sent.

Common Mistakes to Avoid

  • Using formaction on type="button": Form override attributes only trigger on submit controls (type="submit" or type="image").

  • Forgetting that form="id" still relies on unique IDs: If two forms share an ID, external inputs cannot bind reliably.

  • Skipping server authorization on alternate formaction endpoints: Secure /draft and /publish routes equally on the backend.

Frequently Asked Questions

When is formnovalidate most useful?

Use formnovalidate on a "Save Draft" button so users can save half-finished work without filling out every required field first.

Can an input outside a form tag really submit with the form?

Yes. Setting form="my-form-id" attaches any external input or submit button directly to the form whose id is my-form-id.

Conclusion

HTML input form attributes give you fine control over a single form without extra JavaScript. Use formaction to route buttons to different endpoints, formnovalidate for drafts and cancel actions, formmethod and formtarget for special cases like previews, and form="id" to attach fields that live elsewhere in the page. Keep IDs unique, set button types explicitly, and treat every alternate endpoint as something that needs full server-side protection.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
HTML Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum