DevToolsmith

PNG MIME Type

image/png is the MIME type for PNG images. Here is the Content-Type header to send, the file signature, and how to configure servers and code.

MIME type
image/png
Extensions
.png
Content-Type header
image/png
Registered
Yes, with IANA
Compress with gzip
No, it is already compressed
Category
Images

About PNG image files

Lossless, with full transparency, which makes it the format for screenshots, logos and UI graphics. Photos as PNG are several times larger than JPEG, WebP or AVIF. PNG data is already deflate-compressed, so don’t gzip it again on the server; use an optimizer such as oxipng instead.

File signature

PNG files start with 89 50 4E 47 0D 0A 1A 0A ("\x89PNG\r\n\x1a\n"). The extension and the type a browser reports for an upload both come from the file name, so check these bytes on the server before trusting a file.

Serve .png with the right Content-Type

Response header
Content-Type: image/png
nginx (a line in the types { } block of mime.types)
image/png png;
Apache (.htaccess or server config)
AddType image/png .png
Caddy
@png path *.png
header @png Content-Type "image/png"
Check what a server sends
curl -sI https://example.com/file.png | grep -i '^content-type'
# Content-Type: image/png

Set the type in code

Node.js (Express)
res.set('Content-Type', 'image/png');
// Or make the browser download it:
res.attachment('file.png');
Python
import mimetypes

mimetypes.add_type('image/png', '.png')  # if your system doesn't know it
mimetypes.guess_type('file.png')[0]  # 'image/png'
Go
mime.AddExtensionType(".png", "image/png")
w.Header().Set("Content-Type", "image/png")

Accept .png uploads

HTML
<input type="file" accept=".png,image/png">

The accept attribute only filters the file picker; users can still choose another file. Listing the extension as well as the type matters, because operating systems don’t always report the type you expect.

Related types

  • .jpg (image/jpeg): JPEG image
  • .webp (image/webp): WebP image
  • .avif (image/avif): AVIF image
  • .svg (image/svg+xml): SVG image

More images

.gif , .heic , .ico , .bmp , .tiff . Look up any extension or type with the MIME type lookup.

Sources

Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.

Frequently asked questions

What is the MIME type for .png files?

image/png. The full header is "Content-Type: image/png".

Why does my server send the wrong Content-Type for .png?

Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .png is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".

How can I check that a file really is PNG?

Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. PNG files start with 89 50 4E 47 0D 0A 1A 0A ("\x89PNG\r\n\x1a\n"). The MIME type lookup on this site reads them for you when you drop a file on it.