The font
property in CSS is a shorthand property that sets the font-related properties for an element in a single declaration.
Here is an example of how to use the font
property:
p {
font: 16px Arial, sans-serif;
}
In this example, the font
property sets the font size to 16 pixels and the font family to Arial for the <p>
element.
The font
property can also accept additional values to set the font-related properties for the element separately.
p {
font-size: 16px;
font-family: Arial, sans-serif;
font-style: italic;
font-weight: bold;
}
font-size
property sets the font size, the font-family
property sets the font family, the font-style
property sets the font style, and the font-weight
property sets the font weight for the <p>
element.You can also use the font
property to set the font size as a percentage or using one of the following keywords:
xx-small
- x-small
- small
- medium
- large
- x-large
- xx-large
Here is an example of how to use these keywords:
p {
font: x-large Arial, sans-serif;
}
In this example, the font
property sets the font size to x-large
and the font family to Arial for the <p>
element.
It is generally a good practice to use the font
property to set the font-related properties for an element, rather than using multiple properties, to improve the readability and maintainability of your CSS code.
0 Comments