HTML File Inputs: Selection and Upload Preparation
Select one or more files
A file input lets users choose local files through a browser-controlled picker. The multiple attribute allows more than one file. Selecting a file does not itself upload it. The browser exposes selected files through a FileList, not an arbitrary local path.
<label> Attachments <input type="file" name="attachments" multiple></label>No files are selected initially. The picker can choose several files.
Offer a file-type hint
accept lists allowed suggestions as extensions, MIME types or supported wildcards. It guides the picker but is not a security check. On compatible devices capture can suggest a camera or microphone; it is not a guarantee that capture starts.
<label> Profile image <input type="file" name="photo" accept="image/png,image/jpeg,.webp"></label>The picker is guided toward PNG, JPEG and WebP files.
Prepare an upload form
To send file contents through a normal HTML form, use POST and multipart/form-data. The form below illustrates an endpoint; it has no submit button or server implementation. Server code must enforce file size, content type, authorization and safe storage rules.
<form action="/upload" method="post" enctype="multipart/form-data"> <label> Document <input type="file" name="document" accept=".pdf"> </label></form>The form declares the correct encoding for a file upload. Nothing is sent in this demonstration.
Common mistakes and practice
Never use accept, an extension, or the browser-provided MIME type as the only validation. Never prefill a file input with a real local path. Avoid putting sensitive files into an educational playground. Use sample files only.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML File Inputs: Selection and Upload Preparation — Knowledge Check
Apply the control concepts taught in this lesson.
Does selecting a file automatically upload it?
What does accept do?
Which encoding sends file contents with a normal POST form?
Which attribute permits selection of more than one file?
What must a server do even when accept specifies .pdf?