Skip to main content

Understanding Text Properties in CSS Typography (Live Playground)

Text properties in CSS help style and format the text on your web pages. In this tutorial, you will learn about the most important text properties and how to use them, along with sample code and simple explanations.

Text alignment

The text-align property is used to set the horizontal alignment of the text.

Example:

CSS
.center {
text-align: center;
}

In this example, the text-align property is set to center, centering the text inside elements with the center class.

Live Playground, Try it Yourself

Line height

The line-height property is used to control the vertical spacing between lines of text.

Example:

CSS
p {
line-height: 1.6;
}

In this example, the line-height property is set to 1.6, which means the vertical space between lines of text is 1.6 times the font size.

Live Playground, Try it Yourself

Text indentation

The text-indent property is used to indent the first line of a text block.

Example:

CSS
p {
text-indent: 2em;
}

In this example, the text-indent property is set to 2em, which means the first line of each paragraph will be indented by a distance equal to twice the font size.

Live Playground, Try it Yourself

Text decoration

The text-decoration property is a shorthand for setting the text-decoration-line, text-decoration-style, and text-decoration-color properties, which define the appearance of underlines, overlines, and line-throughs.

Example:

CSS
.strike {
text-decoration: line-through solid red;
}

In this example, the text-decoration property is set to line-through solid red, creating a solid red line through the text inside elements with the strike class.

Live Playground, Try it Yourself

Word and letter spacing

The word-spacing and letter-spacing properties are used to control the spacing between words and letters, respectively.

Example:

CSS
p {
word-spacing: 0.2em;
letter-spacing: 0.05em;
}

In this example, the word-spacing property is set to 0.2em, increasing the space between words by 0.2em, and the letter-spacing property is set to 0.05em, increasing the space between letters by 0.05em.

Live Playground, Try it Yourself

Conclusion

By understanding and using text properties in CSS, you can style and format the text on your web pages to create visually appealing and easy-to-read content. These properties allow you to fine-tune the appearance of your text, ensuring that it matches your design requirements and enhances the overall user experience.