CSS font

CSS font properties are probably one of the most important property of a document. When you specify a font in your CSS file and the end user doesn't have that purticular font installed on his system, then the browser will display the text with its default font installed on that system.

How to set CSS Font properties ?

You can sets several Font properties in your CSS file; font-family, font-size , font-style are the primary font peoperties that a user can sets frequently.

font-family

Using font-family property you can specify the typeface of a font that display a text.

CSS - font family

output

CSS - font face

You can set more than one typeface in the font-family properties , browser will prefer the first one that the end user has installed on his computer. It is important to note that the names of each font are case insensitive .

font-size

The font-size property is to change the size of a font to bigger or smaller. You can use CSS Measurements like pixels, ems and percentage to change the size of a font.

CSS - font size

You can set CSS font-size values in absolute and relative sizes. Absolute size sets font to a fixed size and relative size sets font relative to surrounding elements.

Pixel (PX) is the most frequently used size unit but if you use em then can avoid browser resizing problem.

em represents the current browser font size that is 1em is equal to the current font size of the browser. When compared to pixel you can calculate the size of em with following formula pixels/16=em .

You can change the size of the font using percentage values, font-size:100%; means that the font size is using browser's current font size. If you want to increase the font size you can increase the percentage value and for decrease the font size, yo can decrease the percentage value.

The above code will double the font size from the current font size of the browser.

The above code will half the font size from the current font size of the browser.

CSS font size in percentage

font-style

CSS provided two font-style that you can change, they are italic or oblique

CSS font style

Other font properties:

font-weight

When you want to display your font thicker then you can use font-weight properties.

You can change the font-weight values to normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900.

font-variant

The font-variant property helps you to change all lowercase letters are converted to uppercase letters, when compared to other text the converted uppercase letters appears in a smaller font size than the original uppercase letters.

The following source code combining most of the above mentioned pproperties in a single documnet.

output

CSS font