Selecting a Font Family
Description
The font-family
property specifies the fonts in order of preference.
The browser begins with the first font and use the available one.
CSS defines some generic fonts that are available everywhere. There can be variations in the exact font that is used by a browser to render them. A summary of the generic font families can be found in the following table.
Generic Font Family | Example Implementation Font |
serif | Times |
sans-serif | Helvetica |
cursive | Zapf-Chancery |
fantasy | Western |
monospace | Courier |
Example
The following code shows the font-family property applied to a block of text.
<!DOCTYPE HTML>
<html>
<head>
<style>
p {<!--from ww w. j a v a 2 s .c om-->
padding: 5px;
border: medium double black;
background-color: lightgrey;
margin: 2px;
float: left;
font-family: "HelveticaNeue Condensed", monospace;
}
</style>
</head>
<body>
<p>
this is a test.
</p>
</body>
</html>
If HelveticaNeue Condensed is not available in your system, the generic monospace is used.