Fonts
Set font families, font weights, and readable typography.
Fonts play a major role in how a website looks and feels. The same content can appear professional, modern, elegant, or playful simply by changing the font style. CSS provides several properties that allow developers to control the appearance of text and create a better reading experience for users.
When visitors arrive on a website, they spend most of their time reading content. Choosing the right font helps make that content clear, attractive, and easy to understand.
Why Fonts Are Important
Good font choices help:
- Improve readability
- Create a professional appearance
- Strengthen brand identity
- Enhance user experience
- Make content more engaging
For example, a news website typically uses simple and easy-to-read fonts, while a creative design portfolio might use more stylish fonts to showcase personality.
Setting a Font Family
The font-family property defines which font should be used for text.
Example
body {
font-family: Arial, sans-serif;
}In this example:
- Arial is the preferred font.
- sans-serif acts as a backup if Arial is not available.
It is always a good idea to provide a backup font.
Common Font Families
Some popular fonts include:
- Arial
- Verdana
- Times New Roman
- Georgia
- Courier New
Different fonts create different visual impressions, so choose them carefully.
Changing Font Size
The font-size property controls how large or small text appears.
Example
h1 {
font-size: 36px;
}
p {
font-size: 16px;
}Larger font sizes are typically used for headings, while smaller sizes are used for regular content.
Adjusting Font Weight
The font-weight property controls the thickness of text.
Example
h1 {
font-weight: bold;
}
p {
font-weight: normal;
}You can also use numeric values:
h1 {
font-weight: 700;
}Higher numbers create thicker text.
Using Font Style
The font-style property is commonly used to make text italic.
Example
p {
font-style: italic;
}Italic text is often used for quotes, notes, or emphasis.
Using Google Fonts
Modern websites often use custom fonts from Google Fonts.
Example
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">body {
font-family: 'Poppins', sans-serif;
}Google Fonts provides hundreds of free fonts that can make websites look more modern and unique.
Combining Font Properties
You can combine multiple font settings together.
Example
h1 {
font-family: Arial, sans-serif;
font-size: 32px;
font-weight: bold;
font-style: italic;
}This creates a large, bold, italic heading using the Arial font.
Real-World Example
Imagine you are creating an online learning website:
- Use a clean font like Poppins or Arial for articles.
- Make headings larger and bold.
- Use italic text for important notes.
- Keep paragraph text easy to read on both desktop and mobile devices.
These small font adjustments can greatly improve the learning experience for users.
Conclusion
CSS fonts help control how text appears on a webpage. By using properties such as font-family, font-size, font-weight, and font-style, developers can create attractive and readable designs. Choosing the right fonts is not just about appearance; it also improves usability and helps visitors enjoy the content. Understanding CSS fonts is an essential skill for creating professional and user-friendly websites.