Premium CSS Course

CSS Text Styling

CSS offers a variety of properties to control how text is displayed, including properties for alignment, transformation, decoration, and spacing. These allow you to fine-tune the presentation of text on your web pages.

Text Alignment

The text-align property is used to set the horizontal alignment of text within an element. Common values include left, right, center, and justify.


        p {
            text-align: center;
        }
    

This example will center-align all <p> elements on the page.

Text Transform

The text-transform property controls the capitalization of text. You can use uppercase, lowercase, capitalize, or none.


        h1 {
            text-transform: uppercase;
        }
    

This will convert all <h1> text to uppercase.

Text Transform Values

Text Decoration

The text-decoration property allows you to apply decorations to text, such as underlines, overlines, and line-throughs.


        a {
            text-decoration: underline;
        }
    

This will underline all <a> elements, such as links.

Text Decoration Values

Text Shadow

The text-shadow property adds shadow effects to text. It requires values for horizontal and vertical offsets, blur radius, and color.


        h2 {
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }
    

This example will add a subtle shadow to <h2> elements.

Text Shadow Syntax

Letter Spacing

The letter-spacing property controls the spacing between characters in text. Increasing the value spreads the letters apart, while decreasing it brings them closer together.


        h1 {
            letter-spacing: 2px;
        }
    

This will add extra space between the letters in <h1> elements.

Word Spacing

The word-spacing property controls the spacing between words. Increasing the value creates more space between words, while decreasing it reduces the space.


        p {
            word-spacing: 5px;
        }
    

This will increase the space between words in all <p> elements.

Text Indentation

The text-indent property is used to specify the indentation of the first line of text within an element.


        p {
            text-indent: 30px;
        }
    

This will indent the first line of every <p> element by 30px.

Best Practices for Text Styling