Exforsys

Home arrow Technical Training arrow CSS Tutorials

CSS - Working with Fonts

Author : Exforsys Inc.     Published on: 12th Mar 2006    |   Last Updated on: 17th Apr 2006

CSS Fonts

In this tutorial you will learn about Cascading Style Sheets (CSS), Fonts, Font family,Font size, Font weight, Font style and Font variant.

Ads

Font family

To set the font for a specific text, use the property “font-family”, the value can be more than one family separated with a comma, the browser will display the text using the first font, if it's not supported by the operating system, it will use the next font, if no font is supported, it will use the default font.

Example:

body
{
font: Arial, Helvetica, sans-serif;
}

This sets the HTML document font to one of the specified fonts starting from left, if no font is supported, then the browser default font is used.

Font size

To set the font size, use the property “font-size”, the value can be one of the following values:
xx-small, x-small, small, medium, large, x-large, xx-large, smaller, or larger
It can be also a length value or a percentage.

Example:

Body
{
font-size: 12px;
}

This sets the font size of the whole HTML document to 12 pixels.

Font weight

To set the weight of a font, use the property “font-weight”, the value can be one of the following values:
normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, or 900

Example:

.strong
{
font-weight: bold;
}

This sets all the text of the elements that use this class to be bold.

Font style

To set the style of a font, use the property “font-style”, the value can be one of the following values:
normal, italic, or oblique.

Example:

.italic
{
font-style: italic;
}

This sets all the text of the elements that use this class to be italic.

Ads

Font variant


To set the variant of a font, use the property “font-variant”, the value can be one of the following values:
normal or small-caps.

Example:

.caps
{
font-variant: small-caps;
}

This sets all the text of the elements that use this class to be uppercase.

Read Next: CSS Borders


 
This tutorial is part of a CSS Tutorials tutorial series. Read it from the beginning and learn yourself.

CSS Tutorials

 

Comments