Fonts

Font Families

font-family takes a list of fonts. The browser uses the first one available, so always end with a generic family: serif, sans-serif or monospace.

Example

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .serif { font-family: Georgia, "Times New Roman", serif; }
    .sans { font-family: Arial, Helvetica, sans-serif; }
    .mono { font-family: Consolas, "Courier New", monospace; }
  </style>
</head>
<body>

<p class="serif">Georgia is a serif font.</p>
<p class="sans">Arial is a sans-serif font.</p>
<p class="mono">Consolas is a monospace font.</p>

</body>
</html>

Result

Size, Weight and Style

Example

Prefer rem for font sizes: it scales with the user's browser setting (1rem = the root font size, usually 16px):

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    p { font-family: Arial; margin: 4px 0; }
    .small { font-size: 0.875rem; }
    .large { font-size: 1.5rem; font-weight: 700; }
    .italic { font-style: italic; font-weight: 300; }
    .short { font: italic bold 18px/1.4 Georgia, serif; } /* shorthand */
  </style>
</head>
<body>

<p class="small">0.875rem (14px)</p>
<p class="large">1.5rem bold</p>
<p class="italic">Italic, light</p>
<p class="short">The font shorthand</p>

</body>
</html>

Result