CSS text properties are used to control how text looks on a web page—its color, alignment, decoration (underline, line-through), capitalization, spacing, and even shadow. Mastering these properties helps you create clear, readable, and attractive UI text.
color – text colortext-align – horizontal alignment of texttext-decoration – underline, line-through, etc.text-transform – uppercase, lowercase, capitalizeletter-spacing – space between lettersword-spacing – space between wordstext-shadow – adds depth and glow effects to textcolor to match text with your brand or theme.text-align is applied to block-level containers to align inner text.text-decoration is commonly used for links and emphasis.text-transform changes how text appears without changing the actual HTML content.letter-spacing and word-spacing help with readability and design balance.text-shadow can make headings pop or create subtle depth.color)The color property sets the text color. You can use HEX, RGB, HSL, or named colors like red. Always ensure sufficient contrast for accessibility.
// Set paragraph text color using a HEX value
p {
color:#ff5733;
}
This is an example of text with a custom color #ff5733.
text-align)The text-align property controls the horizontal alignment of inline content inside a block-level element. Common values are left, right, center, and justify.
// Center-align text inside a container
.text-box {
text-align:center;
}
This text is centered using text-align: center;.
text-decoration)The text-decoration property adds visual effects such as underline, overline, line-through, or none. It is often used to style links or highlight important text.
// Remove underline from links and add it on hover
a {
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
Hover over this link to see how text-decoration can be applied dynamically.
text-transform)The text-transform property controls the capitalization of text. It does not change the actual text in HTML—only how it is displayed.
uppercase – converts all letters to capitalslowercase – converts all letters to small letterscapitalize – capitalizes the first letter of each word
// Display headings in uppercase without changing HTML text
h2 {
text-transform:uppercase;
}
This text is displayed in uppercase using text-transform: uppercase;.
letter-spacing & word-spacing)Use letter-spacing to control the space between characters and word-spacing for the space between words. These are useful for headings and hero text where typography is important.
// Add spacing to letters and words for a stylized heading
.heading-spaced {
letter-spacing:2px;
word-spacing:5px;
}
This text has letter-spacing and word-spacing applied for better readability.
text-shadow)The text-shadow property adds shadow behind text. It takes values in the order: horizontal offset, vertical offset, blur radius, color.
// Add a soft shadow behind large headings
.hero-title {
text-shadow:2px 2px 4px rgba(0,0,0,0.3);
}
This text has a subtle shadow using text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);.
| Property | Description | Example Values |
|---|---|---|
color |
Sets the text color. | #ff5733, red |
text-align |
Aligns text horizontally. | left, center, right, justify |
text-decoration |
Adds decoration to text. | underline, line-through, none |
text-transform |
Controls capitalization. | uppercase, lowercase, capitalize |
letter-spacing |
Spacing between letters. | 2px, 0.1em |
word-spacing |
Spacing between words. | 5px, 0.2em |
text-shadow |
Adds shadow behind text. | 2px 2px 4px rgba(0, 0, 0, 0.3) |
color, letter-spacing, and text-shadow.text-align: justify; for neat alignment.text-decoration and hover effects.text-transform: uppercase; for emphasis.text-transform: capitalize; for titles or headings that need proper casing.letter-spacing and word-spacing subtly—too much spacing can hurt readability.color or adding text-shadow.text-shadow sparingly to create depth without making text hard to read.color using rgb() or rgba().letter-spacing values on a hero heading.text-transform (without changing HTML).text-shadow to a title and test different blur values.