CSS text-transform property
The text-transform
Property in CSS
The text-transform
property in CSS is used to control the capitalization of text within an element. It allows you to transform text to uppercase, lowercase, capitalize the first letter of each word, or leave it unchanged. This property is useful for adjusting the case of text to fit design requirements or improve readability.
Values of text-transform
none
- Description: The default value. No transformation is applied to the text, and it is displayed in its original case.
- Example:
.no-transform { text-transform: none; /* No transformation applied */ }
capitalize
- Description: Capitalizes the first letter of each word in the text. This is often used for headings or titles.
- Example:
.capitalize { text-transform: capitalize; /* Capitalizes the first letter of each word */ }
uppercase
- Description: Transforms all text to uppercase letters. This is commonly used for emphasis or to create uniform text appearance.
- Example:
.uppercase { text-transform: uppercase; /* Transforms all text to uppercase */ }
lowercase
- Description: Transforms all text to lowercase letters. Useful for making text consistent or for styling purposes.
- Example:
.lowercase { text-transform: lowercase; /* Transforms all text to lowercase */ }
Examples
Capitalized Text
.capitalize-text { text-transform: capitalize; /* Capitalizes the first letter of each word */ }
Uppercase Text
.uppercase-text { text-transform: uppercase; /* Converts all text to uppercase */ }
Lowercase Text
.lowercase-text { text-transform: lowercase; /* Converts all text to lowercase */ }
No Transformation
.no-transform-text { text-transform: none; /* No transformation applied, text displayed as is */ }
Explanation
none
: Text is displayed in its original case without any transformation. This is the default behavior.capitalize
: Capitalizes the first letter of each word, which is useful for titles and headings but may not always be suitable for sentences or body text.uppercase
: Converts all letters to uppercase, which can be useful for creating emphasis or a uniform appearance but may impact readability if overused.lowercase
: Converts all letters to lowercase, which can be useful for creating a uniform style or for specific design effects.
Use Cases
- Headings and Titles: Use
capitalize
oruppercase
to enhance the appearance of headings and titles. - Styling Buttons: Apply
uppercase
to button text to ensure consistency and improve visual impact. - Uniform Text: Use
lowercase
oruppercase
for uniformity in design elements, such as tags or labels.