CSS Text Property
Introduction
The text
property is a shorthand property in CSS that allows you to set multiple text-related properties in a single declaration. It allows you to control the appearance and formatting of text on a web page, such as font size, font family, font style, text alignment, and text decoration.
Basic Usage
To use the text
property, you specify the values for the text-related properties you want to set, separated by spaces. Here is an example of using the text property to set the font size, font family, and font style of an element:
.my-element {
text: 16px Arial italic;
}
In the example above, we are setting the font size of the .my-element
class to 16 pixels, the font family to Arial, and the font style to italic.
Order of Values
The order of the values you specify for the text
property is important. The first value is always the font size, followed by the font family, and then the other text-related properties in the following order:
- font style
- font weight
- font variant
- font stretch
- font size-adjust
- font feature-settings
- font language-override
- text-decoration-line
- text-decoration-style
- text-decoration-color
- text-transform
- text-orientation
- text-combine-upright
- text-indent
- text-align-last
- line-height
- letter-spacing
- word-spacing
- text-decoration
- text-emphasis-style
- text-emphasis-color
- text-emphasis-position
- text-emphasis
- text-shadow
- text-outline
- text-wrap
- text-overflow
- text-overflow-ellipsis
- text-overflow-mode
- white-space
- word-break
- word-wrap
- hyphens
- tab-size
- orphans
- widows
- font-kerning
- font-variant-ligatures
- text-align
- text-justify
Here is an example of using the text
property to set multiple values in the correct order:
.my-element {
text: 16px Arial italic normal normal normal none underline solid #333 none uppercase normal none none none none