How to make file input accept only PDF and XLS and HTML?

Spread the love

Sometimes, we want to make file input accept only PDF and XLS and HTML.

In this article, we’ll look at how to make file input accept only PDF and XLS and HTML.

How to make file input accept only PDF and XLS and HTML?

To make file input accept only PDF and XLS and HTML, we set the accept attribute.

For instance, we write

<input
  name="userfile"
  type="file"
  accept="application/pdf, application/vnd.ms-excel"
/>

to set the accept attribute to the MIME types for PDF and Excel files to only accept PDF and XLS files in our input.

Conclusion

To make file input accept only PDF and XLS and HTML, we set the accept attribute.

Leave a Reply

Your email address will not be published.