About GIF image files
Limited to 256 colours per frame, and animated GIFs are huge compared with video. A muted, looping <video autoplay loop muted playsinline> in MP4 or WebM is often many times smaller for the same clip.
File signature
GIF files start with 47 49 46 38 37 61 or 47 49 46 38 39 61 ("GIF87a" / "GIF89a"). 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 .gif with the right Content-Type
Content-Type: image/gif
image/gif gif;
AddType image/gif .gif
@gif path *.gif
header @gif Content-Type "image/gif"
curl -sI https://example.com/file.gif | grep -i '^content-type'
# Content-Type: image/gif
Set the type in code
res.set('Content-Type', 'image/gif');
// Or make the browser download it:
res.attachment('file.gif');
import mimetypes
mimetypes.add_type('image/gif', '.gif') # if your system doesn't know it
mimetypes.guess_type('file.gif')[0] # 'image/gif'
mime.AddExtensionType(".gif", "image/gif")
w.Header().Set("Content-Type", "image/gif")
Accept .gif uploads
<input type="file" accept=".gif,image/gif">
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
More images
.jpg , .avif , .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 .gif files?
image/gif. The full header is "Content-Type: image/gif".
Why does my server send the wrong Content-Type for .gif?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .gif 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 GIF?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. GIF files start with 47 49 46 38 37 61 or 47 49 46 38 39 61 ("GIF87a" / "GIF89a"). The MIME type lookup on this site reads them for you when you drop a file on it.