We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Returns the media type (MIME) of the file represented by a File object.


var name = file.type;


A string, containing the media type(MIME) indicating what type of the file is it for example "image/png" for PNG images


<input type="file" multiple onchange="showType(this)">
function showType(fileInput) {
  var files = fileInput.files;

  for (var i = 0; i < files.length; i++) {
    var name = files[i].name;
    var type = files[i].type;
    alert("Filename: " + name + " , Type: " + type);

Note: Based on the current implementation, browsers won't actually read the bytestream of a file to determine its media type. It is assumed based on the file extension; a PNG image file renamed to .txt would give "text/plain" and not "image/png". Moreover, file.type is only reliable for common file types like images, documents audio and video. Uncommon file extensions would return an empty string. Developers are advised not to rely on this property as a sole validation scheme.



Specification Status Comment
File API
The definition of 'type' in that specification.
Working Draft Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support13 Yes3.61016 Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes No No No ?

See also

Document Tags and Contributors

 Contributors to this page: fscholz, Jedipedia, stevenwdv, bunnybooboo, vinayk7
 Last updated by: fscholz,