How to get the HTML's input element of "file" type to only accept pdf files?

Viewed 155149

is there any way that html element file

<input name="file1" type="file" style="width:300px">

only accept PDF files and when we browse its only show PDF files...

Thanks

8 Answers

The accept attribute value is a string that defines the file types the file input should accept. You can use the accept attribute like:

<input name="file1" type="file" accept="application/pdf">

or you can specify a unique file type specifier:

<input name="file1" type="file" accept=".pdf">

MDN Reference

Browser Compatibility Check

Related