CSS Fonts
Tuesday, May 27th, 2008One of the most important but overlooked aspects of a web design is the typography. The fonts you use and how you present those fonts can really make or break your website design. Thankfully you can use CSS to really make your fonts look great!
The first thing to learn when it comes to CSS fonts are the selectors and what each of them do. Here are the main font selectors and what they do:
font-family
This selects which font you want to use for your text. You can specify more than one font family, then if the browser cant find the font you use first it will move on to the next one and so on until it finds one it recognises.
font-size
As you might of guessed this defines the size of the font. You can define this as a pixel size (e.g. 12px), as a general size (e.g. large, small etc.).
font-style
The font style attribute defines extra styles to your font such as italic.
font-weight
The font weight sets the weight of the font. To define the weight of your font you can use words (such as normal, bold or bolder) or you can use values (e.g 100, 200, 300 etc.) the higher the values get the bolder the font will get.
These are the main font properties you will use. Now lets have a look at defining a font in CSS. We will add the font to an id called content. Basically this means that everything in the content div will be given the font style we define whilst everything outside the div will have a seperate style.
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
font-style: normal;}
In the example above we first define the font family, you might notice I slected three fonts all seperated by a comma. This is (as described above) so the browser can find another font to use if it cant find arial. Next we define the font size which is pretty self explanitory. Then we define the font weight and font style. As the default for these two values is normal if you didn’t want to have italic or bold text then you wouldn’t have to define them so your css style would look like:
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;}
Now we will move on to writing the above style in shorthand. Writing in shorthand has the same effects as writing it the long way, it just saves some space.
The way the style should be layed out is:
font: font-style font-weight font-size font-family}
So an example of a font style would be:
font: italic bold 12px Arial, Helvetica, sans-serif;}
And that’s all you need to know for the basics of text styling with CSS.

