skip to Main Content

I have not found the examples how to accept any file type by <input type="file">.

When I tried accept="*/*", I has been told

Bad value “/” for attribute “accept” on element “input”: Expected “/” but saw “*” instead."

by the HTML validator.

When I tried accept="", I has been told

Bad value “” for attribute “accept” on element “input”: Expected a MIME type but the literal ended."

by the HTML validator.

When I tried accept="*", I has been told

Bad value “” for attribute “accept” on element “input”: Expected “/” but saw “” instead."

by the HTML validator.

Why are you going to accept any type of files? Usually only one type of files required.

For example it is requires when developing the online files storage like the Google Drive.

2

Answers


  1. List of all the official MIME types

    If you really want to use accept attribute:

    <input
      type="file"
      accept="
        application/*,
        audio/*,
        font/*,
        example/*,
        image/*,
        message/*,
        model/*,
        multipart/*,
        text/*,
        video/*
      "
    >
    

    Or just remove accept attribute :

    <input type="file">
    
    Login or Signup to reply.
  2. To accept any file type without HTML validity violations using the element, you can use the accept attribute with the value "/". Here’s an example:

    <input type="file" accept="*/*">

    The accept attribute specifies the types of files that the input accepts. By setting it to "/", you indicate that the input should accept any file type. This will prevent HTML validity violations related to file type restrictions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search