Input Types

HTML input type="file"

Build a form with the HTML form generator

Select files. The accept attribute is a picker hint, not a security check; validate uploads on the server. The file list is exposed as files; scripts cannot prefill an arbitrary local path. Use multipart/form-data for file upload forms. Use only attributes applicable to this input state; the browser ignores or rejects unrelated constraints. Validate submitted data on the server.

Formal Syntax & Structure

html syntaxhtml
<input type="file">

Parameters & Attributes

NameTypeDescription
typeliteral fileSelects the file input state.
namestringProvides an element-specific name: a form field key, radio group name, named frame, metadata key, slot name or other defined purpose. Its meaning depends on the element; it is not a unique DOM identifier.
disabledbooleanDisables supported controls or elements. Disabled form controls are generally not focusable, validated or submitted. The exact effect depends on the element; disabled="false" still disables.
formform element IDAssociates an eligible control with a form elsewhere in the same document, overriding an ancestor form where applicable. Does not automatically associate descendants of a fieldset.
acceptcomma-separated file typesHints which files a file picker should offer, using extensions, MIME types or supported wildcards. It does not validate uploaded content; check files on the server.
multiplebooleanAllows multiple files, comma-separated email addresses or multiple select options depending on the element. It does not apply to ordinary text inputs.
requiredbooleanMakes supported form controls subject to a nonempty or selected-value constraint. Radio-group and checkbox behavior differs. It does not perform server-side validation.

Return Value

HTMLInputElement

Void form-associated element; no child content. The DOM value and form-submission behavior depend on the input state.

Working Example

Example Snippethtml
<label>  Photo  <input type="file" name="photo" accept="image/*"></label>
HTML Reference