Font family Property in CSS
To specify the font to be used for the text in your website, CSS provides the font-family property.
You may specify primary font family name as the first value and should give the fallback/backup font names as well in the font-family property.
In a case, the browser does not support the primary or first name of the font, it can choose the second one and so on.
Syntax to use CSS font family
This is how the font-family CSS property is defined:
font-family: Verdana, Arial, Times, “Times New Roman”, Serif;
So the font-family keyword is followed by the family name of your choice. The first name should be the one that you intend to use for the particular element (headings, paragraphs, lists etc.) or may be across the site.
The second font family name, which is separated by a comma, is the first backup in case the first font is not available and so on.
If a font name has multiple words, it should be enclosed in the double quotes e.g. “Times New Roman”. If you are using the font family in HTML attribute then it should be enclosed in single quotes.
The last font name in the list should be one of the five generic family names that are always available in HTML and CSS. The five generic font names are:
Example of using font-family
The following example shows how to use the font-family property. The example uses different font family names for headings and paragraph.
/*Using CSS font*/
font-family:Verdana, Arial, Serif;
font-family:“Times New Roman”, Arial, Serif;
font-family:Arial, Verana, serif;
<h1>This is heading 1 with Verdana as primary font-family</h1>
<h2>This is Heading 2 with “Times New Roman” as primary font-family</h2>
<p>This is Paragraph with Arial as primary font-family</p>
As you can see in the demo, the h1 is given Verdana, h2 is “Time New Roman” and <p> tag is given the Arial as primary fonts, which is specified in CSS font-family property.
Also see: CSS font