{"id":266653,"date":"2018-02-23T07:42:35","date_gmt":"2018-02-23T14:42:35","guid":{"rendered":"http:\/\/css-tricks.com\/?p=266653"},"modified":"2020-10-27T08:58:44","modified_gmt":"2020-10-27T15:58:44","slug":"understanding-web-fonts-getting","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/understanding-web-fonts-getting\/","title":{"rendered":"Understanding Web Fonts and Getting the Most Out of Them"},"content":{"rendered":"\n
Thierry Blancpain is a brand and interaction designer at Informal Inquiry<\/a> in New York City and co-founder of Grilli Type<\/a>, a Swiss type foundry. While this article is generally applicable to all web fonts, Grilli Type fonts are used throughout as examples of the concepts, particularly those demonstrating OpenType features.<\/p>\n\n\n\n\n\n\n\n Using your own fonts instead of system fonts is getting easier, but it\u2019s still an evolving field. We\u2019ll go over the different types of font formats and cover tips and best practices for them in this post. We\u2019ll also dive into more in-depth features for those of you who want to level up and aim to perfect the craft with advanced concepts and considerations when using web fonts. In the end, you\u2019ll hopefully feel equipped not only to put web fonts to use but to get the most out of them.<\/p>\n\n\n\n Here we go!<\/p>\n\n\n When you purchase web fonts licensing, you receive a package of font files that typically include at least some of the following formats:<\/p>\n\n\n\n If you are mostly targeting users with modern browsers, you can get away with a progressive method of using If you want to expand support as wide as possible, then add EOT<\/abbr> and TTF<\/abbr> files to the mix. SVG fonts have also been traditionally used for expanding browser support but, at Grilli Type, we don\u2019t offer SVG fonts anymore as they bring with them a number of downsides. Google Chrome for example has even completely removed support for the format.<\/p>\n\n\n We make use of Here\u2019s the deepest level of support, including all of the font file formats we\u2019ve discussed so far:<\/p>\n\n\n\n We can trim things down quite a bit if we’re only aiming to support modern browsers:<\/p>\n\n\n\n Once the font has been declared and defined, we can put it to use on our elements. For example:<\/p>\n\n\n\n One of the most flexible ways to load web fonts is to self-host them. That means that you host the files on your own server and your fonts will always be available when a visitor comes to your website without a third-party dependency. Neither tracking codes nor JavaScript is generally required to load self-hosted font files. Many small type foundries offer fonts as a direct download so they can be self-hosted and at Grilli Type, we are convinced it\u2019s the best way to serve fonts.<\/p>\n\n\n\n While some type foundries offer self-hosting (both with and without cumbersome restrictions and requirements), others only offer hosted solutions, meaning they host the files on your behalf. Some of the well-known ones include Hoefler & Co.<\/a>, Font Bureau<\/a>, and Typotheque<\/a>. Font Bureau and Typotheque offer their fonts in both ways at different price points.<\/p>\n\n\n\n Make sure you know how a type foundry\u2019s web fonts are offered before you buy licensing, because the difference in hosting and the terms of use can affect how they are implemented. Get what makes the most sense for you and fits your needs, and make sure you\u2019re using them legally and according to the foundry\u2019s licensing agreement.<\/p>\n\n\n Let\u2019s take a look at some of the more advanced features of web fonts.<\/p>\n\n\n There are two settings inside font files that define the space between characters<\/a>:<\/p>\n\n\n\n Spacing cannot be turned off at all, because otherwise the text rendering engine (your browser) wouldn\u2019t know what to do with these letters. Kerning, on the other hand, is turned off by default in browsers and has to be turned on by you in your CSS.<\/p>\n\n\n\nFont Formats<\/h3>\n\n\n
@font-face<\/code> that only serves WOFF<\/abbr> and WOFF2<\/abbr> formats. These offer the best compression and allow you to deal with fewer files in your code. And if a user\u2019s machine is so old that it doesn\u2019t support either of these formats, it may be better to just serve them a system font for performance reasons, anyway.<\/p>\n\n\n\n
Embedding Web Fonts<\/h3>\n\n\n
@font-face<\/code><\/a> to include fonts in CSS.<\/p>\n\n\n\n
@font-face {\n font-family: FontName;\n src: url('path\/filename.eot');\n src: url('path\/filename.eot?#iefix') format('embedded-opentype'),\n url('path\/filename.woff2') format('woff2'), \n url('path\/filename.woff') format('woff'),\n url('path\/filename.ttf') format('truetype');\n}<\/code><\/pre>\n\n\n\n
@font-face {\n font-family: FontName;\n src: url('path\/filename.woff2') format('woff2'), \n url('path\/filename.woff') format('woff');\n}<\/code><\/pre>\n\n\n\n
body {\n font-family: 'FontName', Helvetica, Arial, sans-serif;\n}<\/code><\/pre>\n\n\n
Hosting Web Fonts<\/h3>\n\n\n
Advanced Typographic Features<\/h3>\n\n\n
Spacing and Kerning<\/h4>\n\n\n
letter-spacing<\/code><\/a>: This is defined as side bearings on the left and right side of each character<\/li>
font-kerning<\/code><\/a>: This refers to specific adjustments between two characters<\/li><\/ol>\n\n\n\n