font-family

  • Revision slug: CSS/font-family
  • Revision title: font-family
  • Revision id: 19478
  • Created:
  • Creator: McGurk
  • Is current revision? No
  • Comment Updated browser compatibility; 11 words added, 25 words removed

Revision Content

{{ CSSRef() }}

Summary

The font-family CSS property allows for a prioritized list of font family names and/or generic family names to be specified for the selected element. Unlike most other CSS properties, values are separated by a comma to indicate that they are alternatives. The browser will select the first font on the list that is installed on the computer, or that can be downloaded using the information provided by a {{ cssxref("@font-face") }} at-rule.

Web authors should always add at least one generic family in a font-family list, since there's no guarantee that a specific font is intalled on the computer or can be downloaded using a {{ cssxref("@font-face") }} at-rule. The generic family lets the browser select an acceptable fallback font when needed.

It is often convenient to use the shorthand property {{ cssxref("font") }} to set font-size and other font related properties all at once.

Note: The font-family property specifies a list of fonts, from highest priority to lowest. Font selection does not simply stop at the first font named in the list that is on the user's system. Rather, font selection is done one character at a time, so that if an available font does not have a glyph that can display a character needed, the later available fonts are tried. However, this doesn't work in Internet Explorer.

When a font is only available in some styles, variants, or sizes, those properties may also influence which font family is chosen.
  • {{ Xref_cssinitial() }}: depends on user agent
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: yes
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

font-family:  family-or-generic-name [, family-or-generic-name]* | {{ cssxref("inherit") }}

Values

family-or-generic-name

Is either a:

family-name The name of a font family. For example, "Times" and "Helvetica" are font families. Font family names containing whitespace should be quoted.
generic-family

Generic font families are a fallback mechanism, a means of preserving some of the style sheet author's intent in case when none of the specified fonts are available. Generic family names are keywords and must not be quoted. A generic font family should be the a last alternative in the list of font family names.

serif
Glyphs have finishing strokes, flared or tapering ends, or have actual serifed endings.
E.g.  Palatino, "Palatino Linotype", Palladio, "URW Palladio", serif
sans-serif
Glyphs have stroke endings that are plain.
E.g. 'Trebuchet MS', 'Liberation Sans', 'Nimbus Sans L', sans-serif
cursive
Glyphs in cursive fonts generally have either joining strokes or other cursive characteristics beyond those of italic typefaces. The glyphs are partially or completely connected, and the result looks more like handwritten pen or brush writing than printed letterwork.
fantasy
Fantasy fonts are primarily decorative fonts that contain playful representations of characters.
monospace
All glyphs have the same fixed width.
E.g. "DejaVu Sans Mono", Menlo, Consolas, "Liberation Mono", Monaco, "Lucida Console", monospace

Examples

{{ CSSRefExampleLink("font-family") }}

body     { font-family: "Gill Sans Extrabold", Helvetica, sans-serif }

.receipt { font-family: Courier, "Lucida Console", monospace }

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 3.0 3.5 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{ CompatGeckoMobile("1") }} 6.0 6.0 1.0

Specifications

See also

  • Font-related CSS properties: {{ CSS_Reference:Fonts() }}

{{ languages( { "es": "es/CSS/font-family", "fr": "fr/CSS/font-family", "pl": "pl/CSS/font-family" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2>Summary</h2>
<p>The<code> font-family </code>CSS property allows for a prioritized list of font family names and/or generic family names to be specified for the selected element. Unlike most other CSS properties, values are separated by a comma to indicate that they are alternatives. The browser will select the first font on the list that is installed on the computer, or that can be downloaded using the information provided by a {{ cssxref("@font-face") }} at-rule.</p>
<p>Web authors should always add at least one generic family in a font-family list, since there's no guarantee that a specific font is intalled on the computer or can be downloaded using a {{ cssxref("@font-face") }} at-rule. The generic family lets the browser select an acceptable fallback font when needed.</p>
<p>It is often convenient to use the shorthand property {{ cssxref("font") }} to set<code> font-size </code>and other font related properties all at once.</p>
<div class="note"><strong>Note:</strong> The<code> font-family </code>property specifies a list of fonts, from highest priority to lowest. Font selection does <strong>not</strong> simply stop at the first font named in the list that is on the user's system. Rather, font selection is done <strong>one character at a time</strong>, so that if an available font does not have a glyph that can display a character needed, the later available fonts are tried. However, this doesn't work in Internet Explorer.<br> <br> When a font is only available in some <a href="/en/CSS/font-style" title="en/CSS/font-style">styles</a>, <a href="/en/CSS/font-variant" title="en/CSS/font-variant">variants</a>, or <a href="/en/CSS/font-size" title="en/CSS/font-size">sizes</a>, those properties may also influence which font family is chosen.</div>
<ul class="cssprop"> <li>{{ Xref_cssinitial() }}: depends on user agent</li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: yes</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<h2>Syntax</h2>
<pre class="eval syntaxbox">font-family:  <em>family-or-generic-name</em> [, <em>family-or-generic-name</em>]* | {{ cssxref("inherit") }}
</pre>
<h3>Values</h3>
<dl> <dt><strong><em>family-or-generic-name</em></strong></dt>
</dl>
<p style="margin-left: 40px;">Is either a:</p>
<table class="standard-table"> <tbody> <tr> <td><em><strong>family-name</strong></em></td> <td>The name of a font family. For example, "Times" and "Helvetica" are font families. Font family names containing whitespace should be quoted.</td> </tr> <tr> <td><em><strong>generic-family</strong></em></td> <td> <p>Generic font families are a fallback mechanism, a means of preserving some of the style sheet author's intent in case when none of the specified fonts are available. Generic family names are keywords and must not be quoted. A generic font family should be the a last alternative in the list of font family names.</p> <dl> <dt><code>serif</code></dt> <dd style="font-family:Palatino,'Palatino Linotype',Palladio,'URW Palladio',serif">Glyphs have finishing strokes, flared or tapering ends, or have actual serifed endings.<br> E.g.  Palatino, "Palatino Linotype", Palladio, "URW Palladio", serif</dd> <dt><code>sans-serif</code></dt> <dd style="font-family:'Trebuchet MS','Liberation Sans','Nimbus Sans L',sans-serif">Glyphs have stroke endings that are plain.<br> E.g. 'Trebuchet MS', 'Liberation Sans', 'Nimbus Sans L', sans-serif</dd> <dt><code>cursive</code></dt> <dd>Glyphs in cursive fonts generally have either joining strokes or other cursive characteristics beyond those of italic typefaces. The glyphs are partially or completely connected, and the result looks more like handwritten pen or brush writing than printed letterwork.</dd> <dt><code>fantasy</code></dt> <dd>Fantasy fonts are primarily decorative fonts that contain playful representations of characters.</dd> <dt><code>monospace</code></dt> <dd style="font-family:'DejaVu Sans Mono', Menlo, Consolas, 'Liberation Mono', Monaco, 'Lucida Console', monospace">All glyphs have the same fixed width.<br> E.g. "DejaVu Sans Mono", Menlo, Consolas, "Liberation Mono", Monaco, "Lucida Console", monospace</dd> </dl> </td> </tr> </tbody>
</table>
<h3>Examples</h3>
<p>{{ CSSRefExampleLink("font-family") }}</p>
<pre>body     { font-family: "Gill Sans Extrabold", Helvetica, sans-serif }

.receipt { font-family: Courier, "Lucida Console", monospace }
</pre>
<h2 name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>3.0</td> <td>3.5</td> <td>1.0</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoMobile("1") }}</td> <td>6.0</td> <td>6.0</td> <td>1.0</td> </tr> </tbody> </table>
</div><h2>Specifications</h2>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/fonts.html#font-family-prop">CSS 2.1 Fonts #font-family</a></li> <li><a class="external" href="http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property" title="http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property">CSS 3 Fonts #font-family</a> Working draft</li>
</ul>
<h2>See also</h2>
<ul> <li>Font-related CSS properties: {{ CSS_Reference:Fonts() }}</li>
</ul>
<p>{{ languages( { "es": "es/CSS/font-family", "fr": "fr/CSS/font-family", "pl": "pl/CSS/font-family" } ) }}</p>
Revert to this revision