CSS provides several properties to control the appearance and layout of text on web pages. Here’s a detailed breakdown of some essential CSS text properties, including color, alignment, decoration, transform, spacing, and shadow, with examples for each.
Text Color (color)
.text-color {
color: #333333; /* Dark gray text */
}
Text Alignment (text-align)
left, right, center, and justify..text-align {
text-align: center; /* Centers the text horizontally */
}
Text Decoration (text-decoration)
none, underline, overline, line-through, and blink (although blink is deprecated)..text-decoration {
text-decoration: underline; /* Underlines the text */
}
Text Transform (text-transform)
none, capitalize, uppercase, and lowercase..text-transform {
text-transform: uppercase; /* Transforms text to uppercase */
}
Letter Spacing (letter-spacing)
px, em)..letter-spacing {
letter-spacing: 2px; /* Adds 2 pixels of space between characters */
}
Word Spacing (word-spacing)
.word-spacing {
word-spacing: 4px; /* Adds 4 pixels of space between words */
}
Text Shadow (text-shadow)
text-shadow: offset-x offset-y blur-radius color;.text-shadow {
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* Adds a soft black shadow */
}
CSS allows you to combine these properties to create complex text effects.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<style>
.combined-text {
color: hsl(210, 100%, 40%);
text-align: justify;
text-decoration: underline;
text-transform: capitalize;
letter-spacing: 1px;
word-spacing: 2px;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
}
</style>
</head>
<body>
<div class="combined-text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis,
accusamus ullam reiciendis earum nam asperiores eos. Fuga quos dolorem
unde animi saepe accusantium reiciendis quia laborum sequi eligendi
laboriosam quae quis magni adipisci, nam in culpa, reprehenderit nobis non
sunt quasi. Magni labore tenetur eveniet incidunt iste nulla ipsam omnis,
recusandae voluptas facere voluptatem molestias, necessitatibus temporibus
qui pariatur quisquam sed corrupti impedit veniam officia. Esse,
distinctio? Hic et esse sed est eum, ullam aliquid suscipit ducimus omnis
a iusto repudiandae ea voluptatem quidem culpa aspernatur ipsam aperiam
itaque qui, officiis excepturi laboriosam nam veniam rerum. Repellat
eveniet nulla recusandae.
</div>
</body>
</html>
In this combined example:
color: #0066cc; sets the text color to blue.text-align: justify; aligns the text to both the left and right margins.text-decoration: overline underline; applies both overline and underline.text-transform: capitalize; capitalizes the first letter of each word.letter-spacing: 1px; adds space between letters.word-spacing: 2px; adds space between words.text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7); adds a shadow to the text for depth.These properties allow for creative and accessible typography, enhancing the readability and aesthetics of web content.