HTML Attributes
HTML <input> accept Attribute
The accept attribute hints which file types a file-upload input should allow the user to pick. Browsers use it to pre-filter the file picker so users mostly see matching files.
The <input> accept Attribute
The accept attribute is used with <input type="file"> to tell the browser which kinds of files the user is expected to upload. Browsers use it to filter the file picker, so users mostly see matching files. It is only a hint for convenience, not a security guarantee.
It has no effect on any other input type — it only applies when the type is file.
Syntax
Syntax: <input type="file" accept="value">, where value is a comma-separated list of file-type specifiers: file extensions (.pdf), MIME types (image/png) or wildcard MIME types (image/*).
<input type="file" accept=".pdf,.doc,.docx">Example
Run this example and click the file button — the picker will prefer PDFs and Word documents.
<!DOCTYPE html>
<html>
<body>
<form>
<label for="resume">Upload your resume (PDF or Word)</label><br>
<input type="file" id="resume" name="resume"
accept=".pdf,.doc,.docx,application/pdf"><br><br>
<button type="submit">Apply</button>
</form>
</body>
</html>More Examples
Accept only images, allow multiple
<!DOCTYPE html>
<html>
<body>
<form>
<label for="photos">Upload portfolio images</label><br>
<input type="file" id="photos" name="photos"
accept="image/*" multiple><br><br>
<button type="submit">Upload</button>
</form>
</body>
</html>Attribute Values
| Value | Description |
|---|---|
| .ext | A filename extension beginning with a dot, e.g. .pdf or .jpg |
| image/* | Any image file (wildcard MIME type) |
| audio/* | Any audio file |
| video/* | Any video file |
| image/png | A specific MIME type such as PNG images |
| .jpg,.png | A comma-separated list combining multiple specifiers |
accept only filters the picker for convenience. Users can still choose other files, so always validate uploaded file types and sizes on the server as well.
Key Takeaways
- accept works only on <input type="file">.
- Its value is a comma-separated list of extensions, MIME types or wildcards.
- Use image/* style wildcards to accept a whole media family.
- Combine with multiple to allow several files at once.
- It is a hint, not security — always validate on the server.
