CSS provides several properties to control fonts in a webpage, including font family, size, weight, and style. Using these properties correctly ensures that text is readable, stylish, and user-friendly.
Property | Description | Example |
---|---|---|
font-family |
Sets the font type. | font-family: Arial, sans-serif; |
font-size |
Controls the size of text. | font-size: 16px; |
font-weight |
Defines the thickness of text. | font-weight: bold; |
font-style |
Sets normal, italic, or oblique text. | font-style: italic; |
font-variant |
Displays small caps or normal text. | font-variant: small-caps; |
line-height |
Controls spacing between text lines. | line-height: 1.5; |
font-family
)p {
font-family: "Arial", sans-serif;
}
✔ Tip: Always provide a fallback font in case the preferred one is unavailable.
font-size
)Font size can be set using:
font-size: 16px;
).font-size: 1.2em;
).<html>
size (e.g., font-size: 1rem;
).font-size: 120%;
).h1 {
font-size: 24px;
}
font-weight
)This property controls the boldness of text.
font-weight: normal;
font-weight: bold;
p {
font-weight: 600;
}
font-style
)Changes the appearance of the text:
normal
– Default text.italic
– Italicized text.oblique
– Similar to italic but slightly slanted.em {
font-style: italic;
}
font-variant
)Used for small-caps styling, where lowercase letters appear in uppercase but smaller.
p {
font-variant: small-caps;
}
font
)You can set multiple font properties in a single line:
p {
font: italic small-caps bold 16px "Arial", sans-serif;
}
📌 Order:
font-style
font-variant
font-weight
font-size
font-family
Property | Description | Example |
---|---|---|
font-family |
Specifies the font type. | font-family: Verdana, sans-serif; |
font-size |
Defines text size. | font-size: 18px; |
font-weight |
Controls boldness. | font-weight: 700; |
font-style |
Sets normal, italic, or oblique. | font-style: italic; |
font-variant |
Enables small caps. | font-variant: small-caps; |
CSS fonts allow complete control over typography, ensuring better readability and aesthetics. Using proper font sizes, weights, and styles improves user experience. You can also use Google Fonts to enhance the design with custom typography.