mozilla

Revision 19475 of font-family

  • Revision slug: CSS/font-family
  • Revision title: font-family
  • Revision id: 19475
  • Created:
  • Creator: grendel
  • Is current revision? No
  • Comment Removed old browser compatibility table.; 26 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.

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

  • {{ 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 or a generic-family.

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 }

Notes

You should always specify a generic family name as the last value in the font-family property.

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.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.0) 3.0 3.5 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Specifications

See also

{{ CSS_Reference:Fonts() }}

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

Revision Source

<p>{{ CSSRef() }}</p>
<h3>Summary</h3>
<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.</p>
<p>It is often convenient to use the shorthand property {{ cssxref("font") }} to set<code> font-size </code>and other font related properties at one go.</p>
<ul> <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>
<h3>Syntax</h3>
<pre class="eval">font-family:  &lt;family-or-generic-name&gt; [, &lt;family-or-generic-name&gt;]* | {{ cssxref("inherit") }}
</pre>
<h3>Values</h3>
<p><strong>&lt;family-or-generic-name&gt;</strong> is either a <strong>family-name</strong> or a <strong>generic-family</strong>.</p>
<dl> <dt>family-name</dt> <dd>The name of a font family. For example, "Times" and "Helvetica" are font families. Font family names containing whitespace should be quoted.</dd> <dt>generic-family</dt> <dd>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. <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> </dd>
</dl>
<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>
<h3>Notes</h3>
<p>You should always specify a generic family name as the last value in the<code> font-family </code>property.</p>
<p>The<code> font-family </code>property specifies a list of fonts, from highest priority to lowest. Font selection does <em>not</em> simply stop at the first font named in the list that is on the user's system. Rather, font selection is done <em>one character at a time</em>, 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.</p>
<p>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.</p>
<h3 name="Browser_Compatibility">Browser compatibility</h3>
<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 (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>1.0 (1.0)</td> <td>3.0</td> <td>3.5</td> <td>1.0 (85)</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>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody>
</table>
</div>
<h3>Specifications</h3>
<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>
<h3>See also</h3>
<p>{{ CSS_Reference:Fonts() }}</p>
<p>{{ languages( { "es": "es/CSS/font-family", "fr": "fr/CSS/font-family", "pl": "pl/CSS/font-family" } ) }}</p>
Revert to this revision