Languages
[Edit]
EN

HTML - file input only for doc and docx

0 points
Created by:
user4838
728

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

Quick solution:

// ONLINE-RUNNER:browser;

<input type="file" accept=".doc,.docx">

 

Practical example

In this example, we create file input using type="file" attribute. To make it allow only documents, 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=".doc,.docx">
  </label>
</body>
</html>

 

References

  1. <input type="file"> - HTML | MDN
  2. Common MIME types - HTTP | MDN

Alternative titles

  1. HTML - file input only for document files
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