HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <p>A designer's and layout designer's worst nightmare is when a client says, “play around with fonts”. Many people have heard this phrase, but what's the deal with playing around with fonts? CSS provides many rules for styling fonts. Some properties you'll already know are font-weight and font-size.</p>
1 <p>A designer's and layout designer's worst nightmare is when a client says, “play around with fonts”. Many people have heard this phrase, but what's the deal with playing around with fonts? CSS provides many rules for styling fonts. Some properties you'll already know are font-weight and font-size.</p>
2 <p>Besides thickness, CSS allows you to control the following settings:</p>
2 <p>Besides thickness, CSS allows you to control the following settings:</p>
3 <ul><li>Font family</li>
3 <ul><li>Font family</li>
4 <li>Font style</li>
4 <li>Font style</li>
5 <li>Lower case character style</li>
5 <li>Lower case character style</li>
6 <li>Font size</li>
6 <li>Font size</li>
7 <li>Line spacing</li>
7 <li>Line spacing</li>
8 </ul><p>Don't be too scared of these properties, you don't have to use them all straight away. Some of them are used quite rarely.</p>
8 </ul><p>Don't be too scared of these properties, you don't have to use them all straight away. Some of them are used quite rarely.</p>
9 <h2>Font family</h2>
9 <h2>Font family</h2>
10 <p>CSS allows you to specify the fonts to be used on the site. The font-family property is used for this. It takes a list of fonts that can be uploaded to the site. It can be one font family or several at once. If multiple fonts are specified, the browser will read them from left to right until it reaches the first font it can use. Other fonts will be ignored. For example:</p>
10 <p>CSS allows you to specify the fonts to be used on the site. The font-family property is used for this. It takes a list of fonts that can be uploaded to the site. It can be one font family or several at once. If multiple fonts are specified, the browser will read them from left to right until it reaches the first font it can use. Other fonts will be ignored. For example:</p>
11 <p>If the user has the<em>Georgia</em>font in their system, then that font will be used. Otherwise, the browser will look for<em>Times New Roman</em>font. Now, two situations are possible:</p>
11 <p>If the user has the<em>Georgia</em>font in their system, then that font will be used. Otherwise, the browser will look for<em>Times New Roman</em>font. Now, two situations are possible:</p>
12 <ul><li>If the user has the<em>Times New Roman</em>font installed in their system, then that font will be applied to the page</li>
12 <ul><li>If the user has the<em>Times New Roman</em>font installed in their system, then that font will be applied to the page</li>
13 <li>If the user<strong>doesn't have</strong><em>Times New Roman</em>installed in their system, then the browser will use the font from the main settings in their browser. This is necessary to be able to display content on the page</li>
13 <li>If the user<strong>doesn't have</strong><em>Times New Roman</em>installed in their system, then the browser will use the font from the main settings in their browser. This is necessary to be able to display content on the page</li>
14 </ul><p>What font will the browser choose? It all depends on the settings. The standard font may be a different type. This can break the visual part of the site. All fonts can be divided into three large groups:</p>
14 </ul><p>What font will the browser choose? It all depends on the settings. The standard font may be a different type. This can break the visual part of the site. All fonts can be divided into three large groups:</p>
15 <ul><li>Antiqua or serif fonts. These fonts are most often used in books and news sites. In CSS it's designated as a serif</li>
15 <ul><li>Antiqua or serif fonts. These fonts are most often used in books and news sites. In CSS it's designated as a serif</li>
16 <li>Grotesque or sans serif fonts. The main font type on most websites. Right now, you are reading this type of font. In CSS, it's designated as sans-serif</li>
16 <li>Grotesque or sans serif fonts. The main font type on most websites. Right now, you are reading this type of font. In CSS, it's designated as sans-serif</li>
17 <li>Monospace font. Fonts in this family all have symbols of the same width. You may see this font in terminals or code editors. In CSS, it's designated as monospace</li>
17 <li>Monospace font. Fonts in this family all have symbols of the same width. You may see this font in terminals or code editors. In CSS, it's designated as monospace</li>
18 </ul><p>When choosing fonts, you can also specify the main font family. If none of the specified fonts can be found, the browser will pick a system font from the family that was specified. Let's add a default font family to the example. The example uses fonts from the antiqua family, so it's worth adding an appropriate value.</p>
18 </ul><p>When choosing fonts, you can also specify the main font family. If none of the specified fonts can be found, the browser will pick a system font from the family that was specified. Let's add a default font family to the example. The example uses fonts from the antiqua family, so it's worth adding an appropriate value.</p>
19 <p>Always specify a default font family. This is considered good practice because not all fonts may be present on the user's system.</p>
19 <p>Always specify a default font family. This is considered good practice because not all fonts may be present on the user's system.</p>
20 <h2>Installing new fonts</h2>
20 <h2>Installing new fonts</h2>
21 <p>You don't have to rely wholly on system fonts. Projects may use all sorts of various fonts, and a layout designer should be able to add them. The font itself is a file. There can be several such file formats, and it's important to know which browsers support them.</p>
21 <p>You don't have to rely wholly on system fonts. Projects may use all sorts of various fonts, and a layout designer should be able to add them. The font itself is a file. There can be several such file formats, and it's important to know which browsers support them.</p>
22 <ul><li><strong>.woff</strong>/<strong>.woff2</strong>- Web Open Font Format. A common format supported by most modern browsers</li>
22 <ul><li><strong>.woff</strong>/<strong>.woff2</strong>- Web Open Font Format. A common format supported by most modern browsers</li>
23 <li><strong>.ttf</strong>- TrueType. This format was invented in the 1980s and is now used to support older browsers. It's compatible with modern browsers. It's the Goldilocks font format</li>
23 <li><strong>.ttf</strong>- TrueType. This format was invented in the 1980s and is now used to support older browsers. It's compatible with modern browsers. It's the Goldilocks font format</li>
24 <li><strong>.eot</strong>- Embedded OpenType. This is the oldest format. This only needs to be used in older browsers, such as Internet Explorer 6.0, which are supported by your website. This is quite rare, so it's rarely used</li>
24 <li><strong>.eot</strong>- Embedded OpenType. This is the oldest format. This only needs to be used in older browsers, such as Internet Explorer 6.0, which are supported by your website. This is quite rare, so it's rarely used</li>
25 </ul><p>The @font-face rule is used to set the font. It allows you to add the font in various extensions, and define the name and path to the file. We'll use this construction with the<em>Roboto</em>font as an example.</p>
25 </ul><p>The @font-face rule is used to set the font. It allows you to add the font in various extensions, and define the name and path to the file. We'll use this construction with the<em>Roboto</em>font as an example.</p>
26 <p>Let's give our project a<em>fonts</em>directory with font files inside it.</p>
26 <p>Let's give our project a<em>fonts</em>directory with font files inside it.</p>
27 <p>It's good practice to specify @font-face at the beginning of the CSS file, rather than just before the font is used. This allows you to structure CSS better. @font-face takes two properties:</p>
27 <p>It's good practice to specify @font-face at the beginning of the CSS file, rather than just before the font is used. This allows you to structure CSS better. @font-face takes two properties:</p>
28 <ul><li>font-family⁣ - the name of the font to be added. This is where you can access it after the font's been added</li>
28 <ul><li>font-family⁣ - the name of the font to be added. This is where you can access it after the font's been added</li>
29 <li>src⁣ - path to the font file</li>
29 <li>src⁣ - path to the font file</li>
30 </ul><p>You can use the font once you've specified these properties. Add<em>Roboto-Regular</em>.</p>
30 </ul><p>You can use the font once you've specified these properties. Add<em>Roboto-Regular</em>.</p>
31 <p>The next step is to add the other two font styles. You can use the example above. Then our CSS will look like this:</p>
31 <p>The next step is to add the other two font styles. You can use the example above. Then our CSS will look like this:</p>
32 <p>Although this method works, it's a little complicated. Instead of using one font name and the font-weight property to control the font thickness, you have to specify three different names for each font style separately.</p>
32 <p>Although this method works, it's a little complicated. Instead of using one font name and the font-weight property to control the font thickness, you have to specify three different names for each font style separately.</p>
33 <p>@font-face allows you to specify font thickness using font-weight. This allows you to add all the font styles using just one name. Otherwise, the entry is no different from what was in the last example.</p>
33 <p>@font-face allows you to specify font thickness using font-weight. This allows you to add all the font styles using just one name. Otherwise, the entry is no different from what was in the last example.</p>
34 <h2>Font style</h2>
34 <h2>Font style</h2>
35 <p>In addition to the standard font style, CSS allows you to set another way of displaying the font - italic. Use the font-style property for this, it can take one of three values:</p>
35 <p>In addition to the standard font style, CSS allows you to set another way of displaying the font - italic. Use the font-style property for this, it can take one of three values:</p>
36 <ul><li>normal is the standard value. It's the standard way of displaying the font and is the style you're reading right now</li>
36 <ul><li>normal is the standard value. It's the standard way of displaying the font and is the style you're reading right now</li>
37 <li>italic This font has slanted letters, unlike the normal style.<em>This is what italic text looks like</em></li>
37 <li>italic This font has slanted letters, unlike the normal style.<em>This is what italic text looks like</em></li>
38 <li>oblique is also italic. It's often exactly the same as the italic value</li>
38 <li>oblique is also italic. It's often exactly the same as the italic value</li>
39 </ul><p>But why are there two similar values for italics? Actually, they're not that similar. Italic, which is set using italic, is a separate font with its own separate file in the system or on the server. It refers more to cursive text, whereas oblique artificially tilts the characters of the current font.</p>
39 </ul><p>But why are there two similar values for italics? Actually, they're not that similar. Italic, which is set using italic, is a separate font with its own separate file in the system or on the server. It refers more to cursive text, whereas oblique artificially tilts the characters of the current font.</p>
40 <h2>Lower case characters</h2>
40 <h2>Lower case characters</h2>
41 <p>You can use CSS to set the lowercase capital type as small caps.</p>
41 <p>You can use CSS to set the lowercase capital type as small caps.</p>
42 <p>Small caps are lower case letters whose size is the same as (or close to) the size of capital letters. This is often used for style. Look at this paragraph:</p>
42 <p>Small caps are lower case letters whose size is the same as (or close to) the size of capital letters. This is often used for style. Look at this paragraph:</p>
43 <p>Small caps text</p>
43 <p>Small caps text</p>
44 <p>In terms of height, this phrase is no different from a simple set of lowercase characters, but stylistically they look more like capital letters. Small caps are set using the font-variant property. It has two possible values:</p>
44 <p>In terms of height, this phrase is no different from a simple set of lowercase characters, but stylistically they look more like capital letters. Small caps are set using the font-variant property. It has two possible values:</p>
45 <ul><li>normal is the standard lowercase character style</li>
45 <ul><li>normal is the standard lowercase character style</li>
46 <li>small-caps gives small caps</li>
46 <li>small-caps gives small caps</li>
47 </ul><h2>Line spacing</h2>
47 </ul><h2>Line spacing</h2>
48 <p>Line spacing, A.K.A. interline spacing, is the vertical distance between the bottom of one character and the top of another in neighboring lines. This is how the difference between the lines is created. One important element when creating a design is having sufficient space between lines. More often than not, it's 150% of the font-size value. For example, if the font is 16 pixels, then the line spacing should be at least 24 pixels. This value is not a required rule, and you can always diverge from it if you so wish.</p>
48 <p>Line spacing, A.K.A. interline spacing, is the vertical distance between the bottom of one character and the top of another in neighboring lines. This is how the difference between the lines is created. One important element when creating a design is having sufficient space between lines. More often than not, it's 150% of the font-size value. For example, if the font is 16 pixels, then the line spacing should be at least 24 pixels. This value is not a required rule, and you can always diverge from it if you so wish.</p>
49 <p>The line-height property is used to specify line spacing. It can take values with various units of measurement. Typically, a number is used to indicate how much bigger the line spacing is than the font size.</p>
49 <p>The line-height property is used to specify line spacing. It can take values with various units of measurement. Typically, a number is used to indicate how much bigger the line spacing is than the font size.</p>
50 <h2>Shorthand rule</h2>
50 <h2>Shorthand rule</h2>
51 <p>Now you know all the main rules for working with fonts. They are as follows:</p>
51 <p>Now you know all the main rules for working with fonts. They are as follows:</p>
52 <ul><li>font-style</li>
52 <ul><li>font-style</li>
53 <li>font-variant</li>
53 <li>font-variant</li>
54 <li>font-weight</li>
54 <li>font-weight</li>
55 <li>font-size</li>
55 <li>font-size</li>
56 <li>line-height</li>
56 <li>line-height</li>
57 <li>font-family</li>
57 <li>font-family</li>
58 </ul><p>You can specify them not only individually, but also altogether using a single CSS rule, font. It's six different rules within one! This can be very handy if you really need all the values. You don't have to specify all values. The only limitation is that it must include font-size and font-family. The other values can be omitted. Let's specify values for all these properties inside the font rule:</p>
58 </ul><p>You can specify them not only individually, but also altogether using a single CSS rule, font. It's six different rules within one! This can be very handy if you really need all the values. You don't have to specify all values. The only limitation is that it must include font-size and font-family. The other values can be omitted. Let's specify values for all these properties inside the font rule:</p>
59 <p>Pay attention to where it says<em>16px/24px</em>. This is how the font-size and line-height properties are denoted within the font rule.</p>
59 <p>Pay attention to where it says<em>16px/24px</em>. This is how the font-size and line-height properties are denoted within the font rule.</p>
60 <h2>Using one or more rules</h2>
60 <h2>Using one or more rules</h2>
61 <p>This section applies not only to the font rule but to all the abbreviated rules you will learn in the course. On the one hand, it may seem that using one rule reduces the number of lines used in CSS. This is true, but there are two major problems with using such properties:</p>
61 <p>This section applies not only to the font rule but to all the abbreviated rules you will learn in the course. On the one hand, it may seem that using one rule reduces the number of lines used in CSS. This is true, but there are two major problems with using such properties:</p>
62 <ol><li>Remembering the correct order of values. When using abbreviated properties, you should always remember the correct order of property values. It's easy to get that wrong in the early stages of learning. You could try using all the individual properties, but writing them in the order they're used in the abbreviated property. As you gain more experience, you can switch to one rule.</li>
62 <ol><li>Remembering the correct order of values. When using abbreviated properties, you should always remember the correct order of property values. It's easy to get that wrong in the early stages of learning. You could try using all the individual properties, but writing them in the order they're used in the abbreviated property. As you gain more experience, you can switch to one rule.</li>
63 <li>Abbreviated properties override individual ones. If you specify font-variant: small-caps; and then apply font: 16px/24px sans-serif; to the same element, the small caps will be reset to their default value.</li>
63 <li>Abbreviated properties override individual ones. If you specify font-variant: small-caps; and then apply font: 16px/24px sans-serif; to the same element, the small caps will be reset to their default value.</li>
64 </ol><p>You should only use shorthand property once when setting standard or general page styles. For example, the font property will work fine for the body selector, and text modifications can be done using individual properties.</p>
64 </ol><p>You should only use shorthand property once when setting standard or general page styles. For example, the font property will work fine for the body selector, and text modifications can be done using individual properties.</p>