CSS provides a range of properties of style text, including color, alignment, decoration, transformation, and more.
Text Color
The color
property sets the text color.
CSS
x
p {
color: red;
}
Text Alignment
The text-align
property aligns text horizontally.
CSS
p {
text-align: center;
}
Text Decoration
The text-decoration
property adds decorations like underline, overline, or line-through.
CSS
a {
text-decoration: none;
}
Text Transform
The text-transform
property controls the capitalization of text.
CSS
p {
text-transform: uppercase;
}
Text Indent
The text-indent
property indents the first line of text.
CSS
p {
text-indent: 20px;
}
Letter Spacing
The letter-spacing
property adjusts the spacing between letters.
CSS
p {
letter-spacing: 2px;
}
Word Spacing
The word-spacing
property adjusts the spacing between words.
CSS
p {
word-spacing: 5px;
}
Text Shadow
The text-shadow
property adds shadow to text.
CSS
p {
text-shadow: 2px 2px 5px gray;
}
White Space
The white-space
property controls how white space inside an element is handled.
CSS
p {
white-space: nowrap;
}
CSS Text Styling Example Code
HTML/CSS
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Text Styling Example</title>
<style>
p {
color: red;
text-align: center;
text-decoration: underline;
text-transform: uppercase;
text-indent: 20px;
letter-spacing: 2px;
word-spacing: 5px;
text-shadow: 2px 2px 5px gray;
white-space: nowrap;
}
</style>
</head>
<body>
<p>This is styled text.</p>
</body>
</html>
