CSS Custom Fonts
CSS
What Are Custom Fonts?
Custom fonts let you use any font (like Google Fonts or your own files) in your website using CSS — so your design looks consistent across devices.
1. Using Google Fonts
- Step 1: Link the font in your HTML
- Step 2: Use the font in CSS
This will apply the Poppins font to the whole page.
2. Using @font-face (Self-Hosted Fonts)
- Step 1: Upload your font files (.woff, .ttf, etc.)
- Step 2: Declare the font in CSS
- Step 3: Apply it
Font Fallbacks
- Always add a fallback font in case the custom font doesn’t load:
- font-family: 'Open Sans', Arial, sans-serif;
Format | Purpose |
---|---|
.woff2 | Best for web (compressed) |
.woff | Good browser support |
.ttf | Older format |
.otf | Similar to TTF, bigger size |
Method | Usage |
---|---|
Google Fonts | Easy, hosted on Google CDN |
@font-face | For self-hosted custom fonts |
font-family | Apply the font to elements |
Fallback fonts | Provide system-safe backups |