The font-variant property in CSS is used to specify the variant of the font. This property allows you to control the presentation of text in various stylistic and typographic variants.
The font-variant property can take several values. Here are the common values you can use:
Value | Description | Example |
---|---|---|
normal | The default font variant. No special variant applied. |
This is normal variant text.
|
small-caps | Displays lowercase letters as small uppercase letters. |
This is small-caps variant text.
|
initial | Sets this property to its default value. |
This is initial variant text.
|
inherit | Inherits this property from its parent element. |
This is inherit variant text.
|
all-petite-caps | Displays all characters in petite caps (smaller uppercase letters). |
This is all-petite-caps variant text.
|
petite-caps | Displays lowercase letters as petite caps (smaller uppercase letters). |
This is petite-caps variant text.
|
unicase | Displays text in a single case, either all uppercase or all lowercase, depending on the font used. |
This is unicase variant text.
|
titling-caps | Displays text in titling caps, which are uppercase letters designed for use in titles. |
This is titling-caps variant text.
|
Here's how you can apply different font variants to your text using CSS:
Example: Applying Normal Variant
.normal {
font-variant: normal;
}
This will render the text with the normal font variant, which is the default.
.small-caps {
font-variant: small-caps;
}
This will render the text with the small-caps font variant.
.all-petite-caps {
font-variant: all-petite-caps;
}
This will render the text with the all-petite-caps font variant.
.petite-caps {
font-variant: petite-caps;
}
This will render the text with the petite-caps font variant.
.unicase {
font-variant: unicase;
}
This will render the text with the unicase font variant.
.titling-caps {
font-variant: titling-caps;
}
This will render the text with the titling-caps font variant.
Here are some important notes and best practices when using the font-variant property:
Here is a visual comparison of different font variants to help you understand their impact: