HTML accept Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

What You’ll Learn

The accept attribute is a valuable feature in HTML that lets developers specify the types of files a user can select in a file input field. By defining accepted file types, you guide users to upload the correct files and improve form usability.

01

File Type Filter

Limit what the picker shows.

02

Extensions

Use .jpg, .png, .pdf.

03

MIME Types

Use image/* wildcards.

04

input type=file

Where accept applies.

05

JavaScript

Set accept dynamically.

06

Server Validation

Never trust accept alone.

Purpose of accept

The primary purpose of the accept attribute is to define the types of files that are allowed to be selected through a file input element (<input type="file">). It helps users by filtering the displayed files in the file picker and indicating the expected file format.

💡
Client-Side Hint Only

accept improves the user experience but does not enforce file types. Users can still bypass the filter. Always validate uploads on the server.

📝 Syntax

Add accept to an <input type="file"> element with a comma-separated list of file type specifiers:

accept.html
<input type="file" accept=".jpg, .jpeg, .png">

Syntax Rules

  • Only valid on <input type="file"> elements.
  • Separate multiple values with commas (no comma required, but spaces after commas are fine).
  • Values may be file extensions (starting with .) or MIME types.
  • Use multipart/form-data on the parent <form> when uploading files.

💎 Values

The accept attribute accepts one or more file type specifications, each separated by a comma. Specifications can include file extensions or MIME types:

  • accept=".jpg, .jpeg, .png" — Allows only image files with the specified extensions.
  • accept="image/*" — Accepts any image file regardless of the specific extension.
  • accept="application/pdf" — Accepts PDF documents by MIME type.
  • accept="video/*,audio/*" — Multiple MIME type groups in one attribute.
common-values.html
<!-- Extensions -->
<input type="file" accept=".pdf, .docx">

<!-- MIME wildcards -->
<input type="file" accept="image/*">

<!-- Specific MIME -->
<input type="file" accept="image/png, image/jpeg">

⚡ Quick Reference

Use Caseaccept ValueNotes
JPEG/PNG images.jpg, .jpeg, .pngExtension-based filter
Any imageimage/*MIME wildcard
PDF documents.pdf or application/pdfEither form works
Audio filesaudio/*MP3, WAV, etc.
Video filesvideo/*MP4, WebM, etc.
Applicable elementinput type="file"Only file inputs

Applicable Elements

ElementSupported?Notes
<input type="file">YesPrimary and only standard use
<input type="text">Noaccept has no effect
<form>NoUse on the file input inside the form

Examples Gallery

Image uploads, MIME type wildcards, and dynamic accept values with JavaScript.

👀 Live Preview

File input restricted to images with the accept attribute:

Example — Image File Extensions

Let’s look at an example of how to use the accept attribute in an HTML form:

accept.html
<form>
  <label for="fileInput">Select an image file:</label>
  <input type="file" id="fileInput" name="fileInput" accept=".jpg, .jpeg, .png">
  <input type="submit" value="Upload">
</form>
Try It Yourself

How It Works

In this example, the accept attribute specifies that only files with the extensions .jpg, .jpeg, and .png are allowed to be selected.

Example — MIME Type Wildcard

Accept any image format using the image/* MIME type wildcard:

mime-accept.html
<input type="file" accept="image/*">
Try It Yourself

How It Works

The image/* value tells the browser to filter for any file with an image MIME type, including PNG, JPEG, GIF, WebP, and SVG.

Dynamic Values with JavaScript

You can dynamically set the accept attribute using JavaScript to provide a more interactive and customized user experience:

dynamic-accept.html
<input type="file" id="dynamicFileInput">

<script>
  document.getElementById("dynamicFileInput").accept = ".pdf, .docx";
</script>
Try It Yourself

How It Works

In this script, the accept attribute is set to allow only PDF and Word document files for an input with the id dynamicFileInput. This is useful when you want to adjust accepted file types based on user selections or form state.

♿ Accessibility

  • Pair with labels — Use <label for="..."> so users know what file type is expected.
  • Describe accepted types in text — Do not rely on accept alone; add helper text like “PNG or JPG only, max 5 MB.”
  • Announce errors clearly — If server validation rejects a file, explain why in plain language.
  • Do not disable keyboard access — File inputs remain focusable; ensure visible focus styles.

🧠 How accept Works

1

Author sets accept on file input

Define extensions or MIME types in HTML or JavaScript.

Markup
2

User opens file picker

The browser filters visible files to match the accept list.

UX
3

Form submits to server

Server must re-validate type, size, and content independently.

Security
=

Better uploads, safer backend

Users pick the right files; your server enforces the rules.

Browser Support

The accept attribute is supported in all modern browsers on file inputs. Filtering behavior may vary slightly by operating system file picker.

HTML5 · Fully supported

Universal file-type filtering

All major browsers honor accept on input type="file" to guide file selection.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 10+ supported
Full support
Opera Fully supported
Full support
accept attribute 99% supported

Bottom line: Use accept confidently on file inputs; always pair with server-side validation.

💡 Best Practices

✅ Do

  • Clearly communicate accepted file types with labels and helper text
  • Use accept to filter unwanted files and improve UX
  • Validate file types, size, and content on the server
  • Use MIME types when extension alone is insufficient
  • Set enctype="multipart/form-data" on upload forms

❌ Don’t

  • Trust accept as your only validation layer
  • Assume users cannot upload disallowed file types
  • Use accept on non-file input types
  • Forget to handle validation errors gracefully
  • Omit file size limits in your UI and backend

Conclusion

The accept attribute is a valuable tool for controlling the types of files that users can upload through file input elements in HTML. By using this attribute judiciously, you can create forms that are more user-friendly and efficient.

Remember that accept is a helpful guide for users, but it does not enforce server-side validation. Always validate file types on the server to ensure security.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about accept

Bookmark these before your next file upload form.

5
Core concepts
📎 02

Extensions

.jpg, .png, .pdf

Values
🎨 03

MIME Types

image/* wildcards

Values
⚙️ 04

JavaScript

Set accept at runtime

Dynamic
🔒 05

Server Check

Never trust accept alone

Security

❓ Frequently Asked Questions

It specifies which file types a user may select in a file input. The browser filters the file picker accordingly.
<input type="file"> is the standard element. Other input types ignore accept.
.png filters by extension. image/* accepts any image MIME type regardless of extension.
No. accept is a client-side hint only. Always validate file type and content on the server.
Yes. Assign a new value to inputElement.accept based on form state or user choices.
Yes in all modern browsers on file inputs. Filtering details may vary by OS file picker.

Build better file upload forms

Practice the accept attribute with image and document filters in the Try It editor.

Try image upload example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful