About TrueType font files
Desktop font files. Browsers can load them with @font-face, but they are uncompressed and much larger than the same font as WOFF2. Convert them (for example with fonttools’ pyftsubset, which can also strip unused characters) before using them on a site, and check the font’s license allows web embedding.
Other types seen for these files:
application/x-font-ttf
,
application/font-sfnt
. Accept them when reading uploads, but send font/ttf yourself.
File signature
TTF files start with 00 01 00 00. 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 .ttf with the right Content-Type
Content-Type: font/ttf
font/ttf ttf;
AddType font/ttf .ttf
@ttf path *.ttf
header @ttf Content-Type "font/ttf"
curl -sI https://example.com/file.ttf | grep -i '^content-type'
# Content-Type: font/ttf
Set the type in code
res.set('Content-Type', 'font/ttf');
// Or make the browser download it:
res.attachment('file.ttf');
import mimetypes
mimetypes.add_type('font/ttf', '.ttf') # if your system doesn't know it
mimetypes.guess_type('file.ttf')[0] # 'font/ttf'
mime.AddExtensionType(".ttf", "font/ttf")
w.Header().Set("Content-Type", "font/ttf")
Accept .ttf uploads
<input type="file" accept=".ttf,font/ttf">
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
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .ttf files?
font/ttf. You may also see application/x-font-ttf, application/font-sfnt, which are older or unofficial; send font/ttf. The full header is "Content-Type: font/ttf".
Why does my server send the wrong Content-Type for .ttf?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .ttf 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 TTF?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. TTF files start with 00 01 00 00. The MIME type lookup on this site reads them for you when you drop a file on it.