Jump to content

User:Bartlett/09

Ka Wiktionary

Hour 9. Fonts and Font Families

[wax ka badal]
What You'll Learn in This Hour
  • Which font properties specify bold, italic, and variant fonts
  • How you can set a number of font properties at once using a shorthand property
  • What the generic font families are and how to use them
  • Which fonts are most commonly installed on browsers

One of the most effective changes you can make to a web page when using CSS is to simply alter the browser's default font. This can add a more professional look to your website immediately, as well as make it easier for users to read and find information. |}

./ ADD NAME=CH09LEV1SEC1.HTML

Specifying Font Properties

[wax ka badal]

In [file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch02.html#ch02 Hour 2], "Getting Started with CSS," you were introduced to two font properties: font-size and font-family. These enable you to specify the size and typeface of the font, respectively. In addition, a number of other properties can be used to further select fonts from within those families. These properties are font-weight, font-variant, font-style, font-stretch, and font-size-adjust.

To understand how these properties work, it's important to understand how CSS views fonts. A font in CSS is one specific instance of several properties: a specific typeface, size, weight, and other variables. So the font 12pt Arial bold italic is different from the font 10pt Arial. They are part of the same font family, of course. It's helpful to remember that when you declare a font family, you're actually selecting a group of fonts to be used. Other properties (or browser defaults) narrow down the specific font.

Font families generally include a number of variations on the base fontfor example, an italic version of the font. In some cases, you will specify a font combination that simply isn't available as a distinct variant. The browser then has to create a variant on the fly by slanting the text to produce italic effects, for example, or by using the closest available equivalent in the font family.

The effects produced by various font settings are listed in [file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch.htm#ch09table01 Table 9.1] for reference; this is because it's not always clear which property controls which effect.

Property Effect
font-family Selects the typeface family
font-size Sets the size of the font
font-weight Makes text bold or lighter
font-variant Creates "small caps" effect
font-style Sets italic font
text-decoration ([file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch10.html#ch10 Hour 10]) Underlines text
color ([file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch10.html#ch10 Hour 10]) Changes the color of text
line-height ([file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch15.html#ch15 Hour 15]) The height of the line (but not the text height)
font Sets font-family, font-size, font-weight, font-variant, font-style, and line-height
The font-weight Property 

The font-weight property controls how heavy a font appearsin other words, the thickness of the lines used to draw that font, relative to the size of the font. The weight of a font is measured in numbers that range from 100 to 900, in steps of 100. The higher the number, the bolder the font; normal text has a weight of 400 and bold text (as created by the HTML tag) has a weight of 700.

Not all font families have specific fonts at all values; in such a situation, the browser usually uses the closest match. For example, if there's no weight 800 variant for a font, the browser may substitute weight 700.

Many browsers support only two to four font-weight values. [file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch.htm#ch09fig01 Figure 9.1] shows how Safari displays each font-weight value of Verdana, whereas [file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch.htm#ch09fig02 Figure 9.2] is from Firefox. Notice that they differ on whether weight 600 should be weighted like 500, 700, or somewhere in between. Keep this in mind; it will be important later on.

Figure 9.1. Successive font-weight values of Verdana font, shown in Safari.
[file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/images/09fig01_alt.jpg [View full size image]]
File:09fig01.jpg
Figure 9.2. Successive font-weight values of Verdana font, shown in Firefox.
[file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/images/09fig02_alt.jpg [View full size image]]
File:09fig02.jpg

In addition to numeric values, the font-weight property can take named values, as shown on [file:///C:/Documents%20and%20Settings/dani/Asztal/Sams%20Teach%20Yourself%20CSS%20in%2024%20Hours_2ndEd/0672329069/ch.htm#ch09table02 Table 9.2]. The font-weight value is inherited from the containing box if any is set. The default value is normal (400) for most HTML tags; some, such as , ,

to