MyInternships.in

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/*).

The basic pattern
Example
<input type="file" accept=".pdf,.doc,.docx">

Example

Run this example and click the file button — the picker will prefer PDFs and Word documents.

Accept PDFs and Word documents for a resume upload
Example
<!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

Image-only upload that accepts several files
Example
<!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

ValueDescription
.extA 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/pngA specific MIME type such as PNG images
.jpg,.pngA 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.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships