CKTIS / HTML
formtarget — where a form submission result is displayed
The formtarget attribute selects where a submission triggered by a particular button loads its result. It overrides the form's target for that submission, allowing the current tab, a new window or tab, or a named frame to be used.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
formtarget="_self|_blank|_parent|_top|target-name"formtarget specifies the target navigable for a form submission. It applies to submit buttons: button with type submit, and input with type submit or image. It is not an attribute of the form element or an ordinary text field.
The value on the button used to submit takes precedence over the associated form's target. Omitting formtarget leaves target selection to the form. The attribute does not change the request URL, method, or data; formaction overrides the URL, and formmethod overrides the method.
The value is a valid target name or keyword. _self means the current context, _blank a new top-level context, usually a tab or window, _parent the parent context, and _top the topmost context. Without a parent, _parent and _top act like _self. A name such as preview can select an iframe with a matching name; an id alone is insufficient. This is a string-valued attribute, not a boolean attribute.
Open demo.html through a local HTTP server; no server-side code is needed. The script automatically calls requestSubmit() for each button. Standard uses the form's _self target (the current page), while Preview sets formtarget="preview", overriding target="_self" and selecting the named iframe. The submit handler calls preventDefault(), so neither button submits the form or causes navigation. The console reports the selected targets, not a loaded result.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Button-specific form target</title>
</head>
<body>
<h1>Choose a form target</h1>
<form id="example" action="#result" target="_self">
<button type="submit">Standard</button>
<button type="submit" formtarget="preview">Preview</button>
</form>
<p id="result">Local destination for this example.</p>
<iframe id="preview-frame" name="preview" title="Local preview" srcdoc="<p>Local preview frame.</p>"></iframe>
<script>
const form = document.getElementById('example');
const frame = document.getElementById('preview-frame');
form.addEventListener('submit', event => {
event.preventDefault();
const button = event.submitter;
const target = button.hasAttribute('formtarget') ? button.formTarget : form.target;
const destination = target === '_self' ? 'current page' :
window.frames[target] === frame.contentWindow ? 'named iframe' : 'unmatched target';
console.log(`${button.textContent}: ${target} (${destination})`);
});
for (const button of form.querySelectorAll('button')) {
form.requestSubmit(button);
}
</script>
</body>
</html>Result
Standard: _self (current page) Preview: preview (named iframe)
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.