Languages
[Edit]
EN

HTML - file input only for PDFs

0 points
Created by:
Elias999
819

In this article, we would like to show you how to create file input only for pdf files in HTML.

Quick solution:

// ONLINE-RUNNER:browser;

<input type="file" accept="application/pdf,application/x-pdf,application/x-bzpdf,application-gzpdf">

or:

// ONLINE-RUNNER:browser;

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

 

Practical example

In this example, we create file input using type="file" attribute. To make it allow only pdf files, we set accept attribute to the types that file input should accept.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <label>
    <span>Choose a file:</span>
    <input type="file"
           name="picture"
           accept="application/pdf,application/x-pdf,application/x-bzpdf,application-gzpdf">
  </label>
</body>
</html>

 

References

  1. <input type="file"> - HTML | MDN
  2. Common MIME types - HTTP | MDN
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join