Opting for the appropriate font significantly influences the user experience of a website.
A suitable font can establish a distinct brand identity.
Prioritizing legibility in font selection is crucial, as it enhances the value of your content. Additionally, selecting the right color and text size complements the chosen font.
CSS categorizes fonts into five generic font families:
Each font name falls under one of these generic font families.
Note: Sans-serif fonts are generally regarded as more readable on computer screens compared to serif fonts. |
Generic Font Family |
Examples of Font Names |
Serif |
Times New Roman |
Sans-serif |
Arial |
Monospace |
Courier New |
Cursive |
Brush Script MT |
Fantasy |
Copperplate |
In CSS, the font-family property is utilized to designate the font for text.
Note: When the font name consists of more than one word, it must be enclosed in quotation marks, such as: “Times New Roman”. |
Tip: For the font-family property, it’s advisable to include multiple font names as a “fallback” system to enhance compatibility across various browsers and operating systems. Begin with the desired font and conclude with a generic family, allowing the browser to select a similar font from the generic family if the specified fonts are unavailable. Separate font names with commas. Further details on fallback fonts are covered in the following chapter.
Example
Designate various fonts for three paragraphs.
.p1 { font-family: “Times New Roman”, Times, serif; } .p2 { font-family: Arial, Helvetica, sans-serif; } .p3 { font-family: “Lucida Console”, “Courier New”, monospace; } |