Take the 2-minute tour ×

On an HTML page, using the INPUT tag, how can you get it so that when you click the browse button that it filters for image files only? Bonus points if it can include .bmp files.

share|improve this question

6 Answers 6

up vote 0 down vote accepted

With the accept attribute, you list the mime types to accept.

<form action="form_action.asp" accept="image/gif, image/jpeg">
    Your image: <input type="file" name="pic" id="pic" /><br />

Taken from here.

share|improve this answer
This is ignored by almost all webbrowsers. –  BalusC May 18 '10 at 22:55
yep, i just tried their example and it doesnt work. This answer was very helpful though. Although David deserves the points for this he already has 36k points! –  djangofan May 19 '10 at 16:50

In theory, with the accept attribute.

In practice, you can't.

I believe most people who want to do this resort to Flash.

share|improve this answer

The accept attribute of the HTML <form> element is meant for that, but this optional attribute is ignored by almost all webbrowsers. The answer is Flash or Java Applet. For both there exist 3rd party programs. E.g. Uploadify, SWFUpload and JumpLoader. Uploadify has my recommendation.

share|improve this answer

What you're talking about is the accept attribute, which unfortunately, isn't supported by any browser.

share|improve this answer

Supposedly, you should use the "accept" attribute with the correct MIME type like so:

<input type="file" name="pic" id="pic" accept="image/bmp" />

Sadly, this isn't currently supported by any browsers. You can however validate the file using javascript afterwards. Here is a useful link with code: http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

Hope this helps!

share|improve this answer

Use the "accept" attribute on your input tag.


<input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />

EDIT: On further reading, it seems this isn't properly supported by any major browsers and therefore shouldn't be used. Instead it look like you'll need to use some sort of server-side or JavaScript validation instead.

share|improve this answer

Your Answer


