P粉0777017082023-08-30 15:14:03
It's not important to understand all possible format values - since many of them originate from experimental browser implementations.
In fact, you might compare some formatting values to CSS browser prefixes - fortunately, they have become less relevant - unfortunately, they are still sometimes relevant.
Refer to your first @font-face
example:
@font-face { font-family: 'Example'; src: url('Example.eot'); src: url('Example.eot?#iefix') format('embedded-opentype'), url('Example.woff2') format('woff2'), url('Example.woff') format('woff'), url('Example.ttf') format('truetype'), url('Example.svg#svgExample') format('svg'); }
.otf
is actually missing - but it has nothing to do with network usage.
src: url("Example.otf") format("opentype");
Similar to truetype, they can be installed locally and used in any desktop application.
In font casting lingo: OTF font files are also known as "post-script flavor" Open Type fonts.
And .ttf/truetype fonts are also called "Truetype flavored" Open Type fonts.
.otf
font lacks advanced file compression compared to woff2.
Only used by Internet Explorer - but even these atrocities are at least capable of rendering ttf/truetype.
.eot
Obsolete
(Unless you need to maintain some embedded systems running on special windows embedded systems).
Only supported by webkit browsers (safari, epiphany, midori) and Android browsers.
However, all of the above browsers also support woff2, woff or truetype.
Most importantly, it is not supported by Chromium/Blink based browsers (opera, Vivaldi, Brave, Internet Explorer 13/Edge) or Firefox.
No .svg
font files are required (although they can be conveniently used as an interchange format for icon generators such as icomoon)
is probably the best supported font format, but not as compact as woff2 or woff.
Additionally, truetype fonts are available in desktop environments and therefore can be installed and used locally in any application.
Still relevant for some use cases (e.g. pdf conversion).
You may encounter old symbols like the ones in this article: css tips
src: url("Example.woff2") format("woff2 supports variations"), url("Example.woff2") format("woff2-variations");
These additional format types originate from a time when variable font support was still experimental.
Today, they are no longer needed - just use normal format identifiers.
Most modern browsers can map font files to font families even without a specified format.
Still, it's a good idea to include them.
Common mistakes:
url('Example.ttf') format('ttf') //not correct
instead of
url('Example.ttf') format('truetype') //correct
@font-face { font-family: 'Example'; src: url('Example.woff2') format('woff2'), url('Example.woff') format('woff'), url('Example.ttf') format('truetype'); font-weight:400; font-style: normal; font-stretch: 100%; } /* next font style: e.g bold italic condensed */ @font-face { font-family: 'Example'; src: url('Example_boldItalicCn.woff2') format('woff2'), url('Example_boldItalicCn.woff') format('woff'), url('Example_boldItalicCn.ttf') format('truetype'); font-weight:700; font-style: italic; font-stretch: 50%; }
In this example, font-weight and other properties contain 2 values to define the range, for example font-weight: 100 1000
.
@font-face { font-family: 'Example; font-style: normal; font-weight: 100 1000; font-stretch: 0% 200%; src: url(Example.woff2) format('woff2'); }