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 FamilyExample Implementation Font
serifTimes
sans-serifHelvetica
cursive Zapf-Chancery
fantasyWestern
monospaceCourier

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>

Click to view the demo

If HelveticaNeue Condensed is not available in your system, the generic monospace is used.





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table