font-family

CSS font-family Property

The font-family property allows creating a prioritized list of font family names and/or generic family names for the selected element.

We use commas to separate the values and show them as alternatives. The browser will select the first font to use if it is available. However, it may be unavailable in some cases like the user’s computer doesn’t have that font. When this situation occurs, the browser will try to use the next alternative to show the texts (or even a character which the first font cannot show).

There are two types of font family names:

family-name: It is the name of a font-family such as “times”, “courier”, “arial”, etc.

generic-family:It is the name of a generic-family such as “serif”, “sans-serif”, “cursive”, “fantasy”, “monospace”.

When the font name has whitespace, it must be enclosed in quotation marks as follows: “Courier New”.

When we want to use unique font-family, we need to use @font-face property.

类目类目
Initial ValueDepends on the browser.
Applies toAll elements. It also applies to ::first-letter and ::first-line.
InheritedYes.
AnimatableNo.
VersionCSS1
DOM Syntaxobject.style.fontFamily = “Verdana,sans-serif”;

A list of fonts is specified, from highest to lowest, by the font-family property. In this case, font selection will not stop at the first font of the list. It is done one character at a time. This means that if an available font doesn’t have a glyph for the character that is needed, the recent fonts will be tried.

Syntax

Syntax

font-family: family-name | generic-family | initial | inherit;

Example of the font-family property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p {
        font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
      }
    </style>
  </head>
  <body>
    <h2>Font-family property example</h2>
    <p>We used "Lucida Grande" font-family for this text.</p>
  </body>
</html>

Values

Values

ValueDescriptionPlay it
family-name generic-familyPrioritized list of font family names and/or generic family names.Play it »
initialMakes the property use its default value.Play it »
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部