Generic Font Family
A generic font family in CSS is a fallback font category that represents a broad class of fonts. It ensures that if a specific font is not available on a user's device or browser, the browser will default to a similar font within that generic family. There are five generic font families in CSS:
serif
- Fonts with decorative strokes at the ends of characters, often used for traditional and formal designs. Examples include Times New Roman, Georgia, and Palatino.
- For example: Lucida Bright, Lucida Fax, Palatino, Palatino Linotype, Palladio, URW Palladio
sans-serif
- Fonts without decorative strokes, known for their clean and modern appearance. Common examples include Arial, Helvetica, and Verdana.
- For example: Open Sans, Fira Sans, Lucida Sans, Lucida Sans Unicode, Trebuchet MS, Liberation Sans, Nimbus Sans L
monospace
- Fonts where each character occupies the same amount of horizontal space, often used for code snippets or typewriter-style text. Examples include Courier New, Consolas, and Monaco.
- For example: Fira Mono, DejaVu Sans Mono, Menlo, Consolas, Liberation Mono, Monaco, Lucida Console
cursive
- Fonts that mimic handwriting or calligraphy, adding a more personalized touch to text. Examples include Comic Sans MS, Brush Script, and Snell Roundhand.
- For example: Brush Script MT, Brush Script Std, Lucida Calligraphy, Lucida Handwriting, Apple Chancery
fantasy
- Fonts that don't fit into the other categories, often unique or decorative in style. They are typically used for special effects or artistic purposes. Examples include Impact, Papyrus, and Chalkboard.
- For example: Papyrus, Herculanum, Party LET, Curlz MT, Harrington
System font, or web-safe font
A system font or web-safe font is one that’s already assumed to be on the vast majority of users’ devices, with no need for a web font to be downloaded.
- Georgia, serif
- 'Palatino Linotype', serif
- 'Book Antiqua', serif
- Palatino, serif
- 'Times New Roman', serif
- 'Brush Script MS', serif
- Arial, sans-serif
- Helvetica, sans-serif
- 'Arial Black', sans-serif
- 'Comic Sans MS', cursive, sans-serif
- Impact, sans-serif
- Charcoal, sans-serif
- 'Lucida Sans Unicode', sans-serif
- 'Lucida Grande', sans-serif
- Tahoma, sans-serif
- Geneva, sans-serif
- 'Trebuchet MS', sans-serif
- Verdana, sans-serif
- Courier, monospace
- 'Courier New', monospace
- 'Lucida Console', monospace
How to use Google Fonts
< !-- By using link -->
< head>
< link rel="preconnect" href="https://fonts.googleapis.com">
< link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
< link href="https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap" rel="stylesheet">
< /head>
< !-- Or by using import -->
style
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap')
style
< !-- Then create a class and use that class -->
.font-ubuntu {
font-family: "Ubuntu", sans-serif;
}
How to use Downloaded Fonts
< !-- Declare -->
@font-face {
font-family: Ubuntu; src: url("../fonts/Ubuntu-Light.ttf");
}
@font-face {
font-family: Ubuntu; font-weight: bold; src: url("../fonts/Ubuntu-Bold.ttf");
}
< !-- How to use -->
.font-ubuntu {
font-family: "Ubuntu", sans-serif;
}