Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

<input type="reset">

BaselineWidely available

<input> elements of typereset are rendered as buttons, with a defaultclick event handler that resets all inputs in the form to their initial values.

Try it

<form>  <div>    <label for="id">User ID:</label>    <input type="text" name="id" />    <input type="reset" value="Reset" />    <input type="submit" value="Submit" />  </div></form>
.controls {  padding-top: 1rem;  display: grid;  grid-template-rows: repeat(3, 1fr);  grid-template-columns: 1fr 2fr;  gap: 0.7rem;}label {  font-size: 0.8rem;  justify-self: end;}input[type="reset"],input[type="submit"] {  width: 5rem;  justify-self: end;}input[type="reset"] {  grid-column: 2;  grid-row: 2;}input[type="submit"] {  grid-column: 2;  grid-row: 3;}

Note:You should usually avoid including reset buttons in your forms. They're rarely useful, and are instead more likely to frustrate users who click them by mistake (often while trying to click thesubmit button).

Value

An<input type="reset"> element'svalue attribute contains a string that is used as the button's label providing the button with anaccessible description. Buttons such asreset don't have a value otherwise.

Setting the value attribute

html
<input type="reset" value="Reset the form" />

Omitting the value attribute

If you don't specify avalue, you get a button with the default label (typically "Reset," but this will vary depending on theuser agent):

html
<input type="reset" />

Using reset buttons

<input type="reset"> buttons are used to reset forms. If you want to create a custom button and then customize the behavior using JavaScript, you need to use<input type="button">, or better still, a<button> element.

A basic reset button

We'll begin by creating a basic reset button:

html
<form>  <div>    <label for="example">Type in some sample text</label>    <input type="text" />  </div>  <div>    <input type="reset" value="Reset the form" />  </div></form>

This renders like so:

Try entering some text into the text field, and then pressing the reset button.

Adding a reset keyboard shortcut

To add a keyboard shortcut to a reset button — just as you would with any<input> for which it makes sense — you use theaccesskey global attribute.

In this example,r is specified as the access key (you'll need to pressr plus the particular modifier keys for your browser/OS combination; seeaccesskey for a useful list of those).

html
<form>  <div>    <label for="example">Type in some sample text</label>    <input type="text" />  </div>  <div>    <input type="reset" value="Reset the form" accesskey="r" />  </div></form>

The problem with the above example is that there's no way for the user to know what the access key is! This is especially true since the modifiers are typically non-standard to avoid conflicts. When building a site, be sure to provide this information in a way that doesn't interfere with the site design (for example by providing an easily accessible link that points to information on what the site access keys are). Adding a tooltip to the button (using thetitle attribute) can also help, although it's not a complete solution for accessibility purposes.

Disabling and enabling a reset button

To disable a reset button, specify thedisabled attribute on it, like so:

html
<input type="reset" value="Disabled" disabled />

You can enable and disable buttons at run time by settingdisabled totrue orfalse; in JavaScript this looks likebtn.disabled = true orbtn.disabled = false.

Note:See the<input type="button"> page for more ideas about enabling and disabling buttons.

Validation

Buttons don't participate in constraint validation; they have no real value to be constrained.

Examples

We've included basic examples above. There isn't really anything more to say about reset buttons.

Technical summary

ValueA string used as the button's label
Eventsclick
Supported common attributestype andvalue
IDL attributesvalue
DOM interfaceHTMLInputElement
MethodsNone
Implicit ARIA Rolebutton

Specifications

Specification
HTML
# reset-button-state-(type=reset)

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp