--- title: slug: Web/HTML/Element/Input translation_of: Web/HTML/Element/input ---

Описание

Элемент HTML <input> используется для создания интерактивных элементов управления в веб-формах для получения данных от пользователя; в зависимости от устройства и {{Glossary("user agent")}}, доступен широкий выбор типов входных данных и виджетов управления. Из-за огромного количества возможных сочетаний типов ввода и атрибутов это один из самых мощных и сложных элементов HTML.

Атрибуты

Этот элемент содержит глобальные атрибуты.

{{htmlattrdef("type")}}
Тип элемента для отображения. Если этот атрибут не указан, по умолчанию используется text. Возможными значениями являются:
{{htmlattrdef("accept")}}
В случае, если значением атрибута type является file, данный атрибут определяет типы файлов, которые сервер может принять. В противном случае файл игнорируется. Значение должно быть списком уникальных спецификаторов типов содержания, разделённым запятыми:
{{htmlattrdef("accesskey")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline", "HTML5")}}
Одиночный символ, который пользователь может нажать, чтобы переключить фокус на элемент управления.
{{htmlattrdef("mozactionhint")}} {{non-standard_inline}}
Определяет "действие-подсказку", которая используется для определения того, как будет обозначаться клавиша enter на мобильных устройствах с виртуальной клавиатурой. Поддерживаемые значения: go, done, next, search, и send; они автоматически сопоставляются с необходимой строкой (являются чувствительными к регистру).
{{htmlattrdef("autocomplete")}} {{HTMLVersionInline("5")}}
Этот атрибут указывает, разрешено ли автоматическое заполнение поля браузером. Разрешено по умолчанию, даже если не указано. Данный атрибут игнорируется, если атрибут type равен hidden, password, checkbox, radio, file, или type кнопка (button, submit, reset, image). Возможные значения:

Если не атрибут autocomplete не указан в <input>, тогда браузер использует атрибут autocomplete формы, которая является родительской для данной формы. The form owner is either the form element that this <input> element is a descendant of or the form element whose id is specified by the form attribute of the input element. For more information, see the {{htmlattrxref("autocomplete", "form")}} attribute in {{HTMLElement("form")}}.

{{htmlattrdef("autofocus")}} {{HTMLVersionInline("5")}}
This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form element in a document can have the autofocus attribute, which is a Boolean. It cannot be applied if the type attribute is set to hidden (that is, you cannot automatically set focus to a hidden control).
{{htmlattrdef("autosave")}} {{HTMLVersionInline("5")}}
This attribute should be defined as a unique value. If the value of the type attribute is search, previous search term values will persist in the dropdown across page load.
{{htmlattrdef("checked")}}
When the value of the type attribute is radio or checkbox, the presence of this Boolean attribute indicates that the control is selected by default; otherwise it is ignored.
{{htmlattrdef("disabled")}}
This Boolean attribute indicates that the form control is not available for interaction. In particular, the click event will not be dispatched on disabled controls. Also, a disabled control's value isn't submitted with the form.
{{htmlattrdef("form")}} {{HTMLVersionInline("5")}}
The form element that the input element is associated with (its form owner). The value of the attribute must be an id of a {{HTMLElement("form")}} element in the same document. If this attribute is not specified, this <input> element must be a descendant of a {{HTMLElement("form")}} element. This attribute enables you to place <input> elements anywhere within a document, not just as descendants of their form elements. An input can only be associated with one form.
{{htmlattrdef("formaction")}} {{HTMLVersionInline("5")}}
The URI of a program that processes the information submitted by the input element, if it is a submit button or image. If specified, it overrides the {{htmlattrxref("action","form")}} attribute of the element's form owner.
{{htmlattrdef("formenctype")}} {{HTMLVersionInline("5")}}
If the input element is a submit button or image, this attribute specifies the type of content that is used to submit the form to the server. Possible values are:

If this attribute is specified, it overrides the {{htmlattrxref("enctype","form")}} attribute of the element's form owner.

{{htmlattrdef("formmethod")}} {{HTMLVersionInline("5")}}
If the input element is a submit button or image, this attribute specifies the HTTP method that the browser uses to submit the form. Possible values are:

If specified, this attribute overrides the {{htmlattrxref("method","form")}} attribute of the element's form owner.

{{htmlattrdef("formnovalidate")}} {{HTMLVersionInline("5")}}
If the input element is a submit button or image, this Boolean attribute specifies that the form is not to be validated when it is submitted. If this attribute is specified, it overrides the {{htmlattrxref("novalidate","form")}} attribute of the element's form owner.
{{htmlattrdef("formtarget")}} {{HTMLVersionInline("5")}}
If the input element is a submit button or image, this attribute is a name or keyword indicating where to display the response that is received after submitting the form. This is a name of, or keyword for, a browsing context (for example, tab, window, or inline frame). If this attribute is specified, it overrides the {{htmlattrxref("target", "form")}} attribute of the elements's form owner. The following keywords have special meanings:
{{htmlattrdef("height")}} {{HTMLVersionInline("5")}}
If the value of the type attribute is image, this attribute defines the height of the image displayed for the button.
{{htmlattrdef("inputmode")}} {{HTMLVersionInline("5")}}
A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is text, password, email, or url. Possible values are:
{{htmlattrdef("list")}} {{HTMLVersionInline("5")}}
В атрибуте указывает id элемента {{HTMLElement("datalist")}}, в котором находится список предопределённых значений для заполнения. Браузер отображает только те варианты, которые соответствуют введённым символами. Этот атрибут игнорируется, когда атрибут type принимает значения hidden, checkbox, radio, file, или type в качестве кнопки.
{{htmlattrdef("max")}} {{HTMLVersionInline("5")}}
The maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.
{{htmlattrdef("maxlength")}}
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in Unicode code points) that the user can enter; for other control types, it is ignored. It can exceed the value of the size attribute. If it is not specified, the user can enter an unlimited number of characters. Specifying a negative number results in the default behavior; that is, the user can enter an unlimited number of characters. The constraint is evaluated only when the value of the attribute has been changed.
{{htmlattrdef("min")}} {{HTMLVersionInline("5")}}
The minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
{{htmlattrdef("minlength")}} {{HTMLVersionInline("5")}}
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in Unicode code points) that the user can enter; for other control types, it is ignored.
{{htmlattrdef("multiple")}} {{HTMLVersionInline("5")}}
Этот Boolean атрибут указывает, может ли пользователь вводить несколько значений. Этот атрибут применяется, если для атрибута type задано значение email или file; в противном случае он игнорируется. 
{{htmlattrdef("name")}}
The name of the control, which is submitted with the form data.
{{htmlattrdef("pattern")}} {{HTMLVersionInline("5")}}
A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored. The regular expression language is the same as JavaScript's. The pattern is not surrounded by forward slashes.
{{htmlattrdef("placeholder")}} {{HTMLVersionInline("5")}}
A hint to the user of what can be entered in the control . The placeholder text must not contain carriage returns or line-feeds. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored.
Note: Do not use the placeholder attribute instead of a {{HTMLElement("label")}} element. Their purposes are different: the {{HTMLElement("label")}} attribute describes the role of the form element; that is, it indicates what kind of information is expected, the placeholder attribute is a hint about the format the content should take. There are cases in which the placeholder attribute is never displayed to the user, so the form must be understandable without it.
{{htmlattrdef("readonly")}}
This Boolean attribute indicates that the user cannot modify the value of the control.

{{HTMLVersionInline("5")}} This attribute is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type.

{{htmlattrdef("required")}} {{HTMLVersionInline("5")}}
This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The {{cssxref(":optional")}} and {{cssxref(":required")}} CSS pseudo-classes will be applied to the field as appropriate.
{{htmlattrdef("selectionDirection")}} {{HTMLVersionInline("5")}}
The direction in which selection occurred. This is "forward" if the selection was made from left-to-right in an LTR locale or right-to-left in an RTL locale, or "backward" if the selection was made in the opposite direction. This can be "none" if the selection direction is unknown.
{{htmlattrdef("size")}}
The initial size of the control. This value is in pixels unless the value of the type attribute is text or password, in which case, it is an integer number of characters. Starting in HTML5, this attribute applies only when the type attribute is set to text, search, tel, url, email, or password; otherwise it is ignored. In addition, the size must be greater than zero. If you don't specify a size, a default value of 20 is used.
{{htmlattrdef("spellcheck")}} {{HTMLVersionInline("5")}}
Setting the value of this attribute to true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked.
{{htmlattrdef("src")}}
If the value of the type attribute is image, this attribute specifies a URI for the location of an image to display on the graphical submit button; otherwise it is ignored.
{{htmlattrdef("step")}} {{HTMLVersionInline("5")}}
Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this attribute is not set to any, the control accepts only values at multiples of the step value greater than the minimum.
{{htmlattrdef("tabindex")}} element-specific in {{HTMLVersionInline(4)}}, global in {{HTMLVersionInline("5")}}
The position of the element in the tabbing navigation order for the current document.
{{htmlattrdef("usemap")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline", "HTML5")}}
The name of a {{HTMLElement("map")}} element to as an image map.
{{htmlattrdef("value")}}
The initial value of the control. This attribute is optional except when the value of the type attribute is radio or checkbox.
Note that when reloading the page, Gecko and IE will ignore the value specified in the HTML source, if the value was changed before the reload.
{{htmlattrdef("width")}} {{HTMLVersionInline("5")}}
If the value of the type attribute is image, this attribute defines the width of the image displayed for the button.
{{htmlattrdef("x-moz-errormessage")}} {{non-standard_inline}}
This Mozilla extension allows you to specify the error message to display when a field doesn't successfully validate.

Notes

File inputs

Note: Starting in {{Gecko("2.0")}}, calling the click() method on an {{HTMLElement("input")}} element of type "file" opens the file picker and lets the user select files. See Using files from web applications for an example and more details.

You can't set the value of a file picker from a script; doing something like the following has no effect:

var e = getElementById("someFileInputElement");
e.value = "foo";

Error messages

If you want Firefox to present a custom error message when a field fails to validate, you can use the x-moz-errormessage attribute to do so:

<input type="email" x-moz-errormessage="Please specify a valid email address.">

Note, however, that this is not standard and will not have an effect on other browsers.

Examples

A simple input box

<!-- A basic input -->
<input type="text" name="input" value="Type here">

A common use-case scenario

<!-- A common form that includes input tags -->
<form action="getform.php" method="get">
    First name: <input type="text" name="first_name" /><br />
     Last name: <input type="text" name="last_name" /><br />
        E-mail: <input type="email" name="user_email" /><br />
<input type="submit" value="Submit" />
</form>

Using mozactionhint on Firefox mobile

You can use the {{htmlattrxref("mozactionhint", "input")}} attribute to specify the text for the label of the enter key on the virtual keyboard when your form is rendered on Firefox mobile. For example, to have a "Next" label, you can do this:

<input type="text" mozactionhint="next" name="sometext" />

The result is:

mozactionhint.png

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'the-input-element.html#the-input-element', '<input>')}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', 'forms.html#the-input-element', '<input>')}} {{Spec2('HTML5 W3C')}}
{{SpecName('HTML4.01', 'interact/forms.html#h-17.4', '<form>')}} {{Spec2('HTML4.01')}}

Совместимость с браузерами

{{Compat("html.elements.input")}}

[1] Распознаётся, но UI отсутствует.

[2] Отсутствует для type="checkbox" и type="radio".

[3] В Safari autocapitalize="words" переводит в верхний регистр каждый второй символ слова.

[4] datetime был удалён из спецификации и браузеров в пользу datetime-local.

[5] См {{bug(1355389)}}

[6] Ещё не имплементировано. Наблюдать: {{bug("888320")}} и TPE DOM/Date time input types.

Gecko notes

Starting in Gecko 9.0 {{geckoRelease("9.0")}}, Firefox for Android lets users capture images using their camera and upload them, without having to leave the browser. Web developers can implement this feature by simply specifying setting the accept attribute's value to "image/*" on their file input, like this:

<input type="file" accept="image/*">

Firefox for Android sets a default {{ cssxref("background-image") }} gradient on all type="text", type="file", type="button", and type="submit" inputs. This can be disabled using background-image: none.

Firefox for Android also sets a default {{ cssxref("border") }} on all <input type="file"> elements.

See also

{{HTMLRef}}