Why should we include ttf, eot, woff, svg,... in a font-face
Asked Answered
P

3

391

In CSS3 font-face, there are multiple font types included like ttf, eot, woff, svg and cff.

Why should we use all of these types?

If they are special to different browsers, why is the number of them greater than the number of the major web browsers?

Possing answered 12/6, 2012 at 18:42 Comment(0)
C
598

Answer in 2019:

Only use WOFF2, or if you need legacy support, WOFF. Do not use any other format

(svg and eot are dead formats, ttf and otf are full system fonts, and should not be used for web purposes)

Original answer from 2012:

In short, font-face is very old, but only recently has been supported by more than IE.

  • eot is needed for Internet Explorers that are older than IE9 - they invented the spec, but eot was a proprietary solution.

  • ttf and otf are normal old fonts, so some people got annoyed that this meant anyone could download expensive-to-license fonts for free.

  • Time passes, SVG 1.1 adds a "fonts" chapter that explains how to model a font purely using SVG markup, and people start to use it. More time passes and it turns out that they are absolutely terrible compared to just a normal font format, and SVG 2 wisely removes the entire chapter again.

  • Then, woff gets invented by people with quite a bit of domain knowledge, which makes it possible to host fonts in a way that throws away bits that are critically important for system installation, but irrelevant for the web (making people worried about piracy happy) and allows for internal compression to better suit the needs of the web (making users and hosts happy). This becomes the preferred format.

  • 2019 edit A few years later, woff2 gets drafted and accepted, which improves the compression, leading to even smaller files, along with the ability to load a single font "in parts" so that a font that supports 20 scripts can be stored as "chunks" on disk instead, with browsers automatically able to load the font "in parts" as needed, rather than needing to transfer the entire font up front, further improving the typesetting experience.

If you don't want to support IE 8 and lower, and iOS 4 and lower, and android 4.3 or earlier, then you can just use WOFF (and WOFF2, a more highly compressed WOFF, for the newest browsers that support it.)

@font-face {
  font-family: 'MyWebFont';
  src:  url('myfont.woff2') format('woff2'),
        url('myfont.woff') format('woff');
}

Support for woff can be checked at http://caniuse.com/woff
Support for woff2 can be checked at http://caniuse.com/woff2

Contrabassoon answered 12/6, 2012 at 18:45 Comment(17)
woff... has a mode that stops people pirating the font? How on earth can/does that work?Speed
Maybe I'm wrong – I'm sure I recall a flag that disabled something like 'desktop mode' to ensure a user couldn't use the font outside of font-face… Perhaps that was an earlier spec?Contrabassoon
From what I see, TTF is lighter than WOFF, so 99% of time there is no reason to use WOFFFlare
TTF shouldn't be lighter than WOFF. WOFF is a compressed form of TrueType - OpenType font (ttf and otf).Sanctify
The point of WOFF is not anti-piracy. TypeKit says, "the two main benefits OpenType/CFF fonts have over TrueType fonts are 1) their smaller file size, and that 2) they require far less hinting information in order to render well in environments that allow some form of anti-aliasing."Wingo
@MarkAmery setting a flag, probably. And expecting people who write woff-to-ttf converters to respect it.Asaasabi
Regardless of the wrong references from caniuse.com, woff is supported at least by Android 4.1.2, I tried it with a Phonegap app successfully.Masseuse
And then there is WOFF2Encroachment
@CamiloMartin But why would someone, who wants to pirate a font suddenly stop because of a flag? I don't get it.Jacquard
@Zelphir tools make it hard to create embeddable fonts with that flag, and your run-off-the-mill designer is programming-illiterate and could only remove the flag if someone designed a Mac app with a shiny "pirate font" button. Moreover, if they are a corporation, you can bring legal charges. If they are some guy with a blog, talk to them, failing that, their host, etc - but keep in mind people who can't buy your font aren't potential costumers anyway, so I'd say free publicity is worth more than the hassle of convincing them to just swap it for the closest thing on dafont.Asaasabi
@Zelphir TL;DR: only become a font designer for passion.Asaasabi
Does the CSS in this answer specify WOFF and WOFF2 in the correct order, if this is a consideration?Uboat
@Uboat first supported format is used, so this will use WOFF2 if supported.Krupp
Correct me if I am wrong, It seems that most newer(2018) browser now prioritize WOFF2/WOFF if file is available.Cuzco
Great question, great answer : just a simple followup question, if you need all 4 files, I assume there is some kind of computer program that makes it possible to export one format to the 4 other ones? (maybe with a template CSS file?) - that would be great. Anybody ?Tail
Really great answer!!! Honestly, if there were a top 100 stack overflow answers list, I would rate this as being near the top. Its very accurate, informative, reads well, grammar & spelling are on point, yet it isn't over elaborated, or more extensive than it needs to be (which is something I often struggle with when I author an answer).Scammony
WOFF does not support Internet Explorer 8 - 11, so if legacy support is something that matters, one has to add the EOT Format. ReferenceYet
S
23

Woff is a compressed (zipped) form of the TrueType - OpenType font. It is small and can be delivered over the network like a graphic file. Most importantly, this way the font is preserved completely including rendering rule tables that very few people care about because they use only Latin script.

Take a look at this website. The font you see is an experimental web delivered smartfont (woff) that has thousands of combined characters making complex shapes. The underlying text is simple Latin code of romanized Singhala. (Copy and paste to Notepad and see).

Only woff can do this because nobody has this font and yet it is seen anywhere (Mac, Win, Linux and even on smartphones by all browsers except by IE. IE does not have full support for Open Types).

Shrive answered 26/5, 2013 at 19:28 Comment(2)
I don't see anything special on that website. If I copy it into an editor (has utf8 support) I still see only normal text. What is it that woff exactly does?Jacquard
Two-thirds of this answer are either wrong or irrelevant. Also that link is broken.Dulcinea
A
17

WOFF 2.0, based on the Brotli compression algorithm and other improvements over WOFF 1.0 giving more than 30 % reduction in file size, is supported in Chrome, Opera, and Firefox.

http://en.wikipedia.org/wiki/Web_Open_Font_Format http://en.wikipedia.org/wiki/Brotli

http://sth.name/2014/09/03/Speed-up-webfonts/ has an example on how to use it.

Basically you add a src url to the woff2 file and specify the woff2 format. It is important to have this before the woff-format: the browser will use the first format that it supports.

Aldehyde answered 15/11, 2014 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.