Open In App

CSS Text Formatting

The CSS text formatting properties are used to format text, style the text, and perform different types of manipulations like word spacing, alignment, justification, and text transformation.

Syntax:

The Syntax to write this property:

Selector {
    property-name : /*value*/
}

CSS Text Formatting Properties: 

These are the following text formatting properties.

Example 1: This example illustrates the use of text color property.

<!DOCTYPE html>
<html>

<head>
    <style>
        h1 {
            color: red;
        }

        h2 {
            color: green;
        }
    </style>
</head>

<body>
    <h1>
        GEEKS FOR GEEKS
    </h1>
    <h2>
        TEXT FORMATTING
    </h2>
</body>

</html>

Output:

chrome-capture-2023-6-5-(1)

Example 2: This example illustrates the use of the text-decoration property.

<!DOCTYPE html>
<html>

<head>
    <style>
        h1 {
            color: red;
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <h1>
        GEEKS FOR GEEKS
    </h1>
    <h2>
        TEXT FORMATTING
    </h2>
</body>

</html>

Output:

chrome-capture-2023-6-5-(3)

Example 3: This example illustrates the use of the text-indent property.

<!DOCTYPE html>
<html>

<head>
    <style>
        h2 {
            text-indent: 80px;
        }
    </style>
</head>

<body>
    <h1>
        GEEKS FOR GEEKS
    </h1>
    <h2>
        This is text formatting properties.<br />
        Text indentation property is used to
        indent the first line of the paragraph.
    </h2>
</body>

</html>

Output:

chrome-capture-2023-6-5-(5)

Example 4: This example illustrates the use of the line-height property.

<!DOCTYPE html>
<html>

<head>
    <style>
        h2 {
            line-height: 40px;
        }
    </style>
</head>

<body>
    <h1>
        GEEKS FOR GEEKS
    </h1>
    <h2>
        This is text formatting properties.<br />
        This property is used to set the
        space between the lines.
    </h2>
</body>

</html>

Output:

chrome-capture-2023-6-5-(7)

Example 5: This example illustrates the use of the direction property. 

<!DOCTYPE html>
<html>
    <head>
        <style>
            h2 {
                direction: rtl;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <h1>
            GEEKS FOR GEEKS
        </h1>
        <h2>
            <bdo dir="rtl">
                This is text formatting properties.
            </bdo>
        </h2>
    </body>
</html>

Output:

chrome-capture-2023-6-5-(8)

Example 6: This example illustrates the use of the text-shadow property. 

<!DOCTYPE html>
<html>

<head>
    <style>
        h1 {
            text-shadow: 3px 1px blue;
        }
    </style>
</head>

<body>
    <h1>
        GEEKS FOR GEEKS
    </h1>
    <h2>
        This is text formatting properties.
    </h2>
</body>

</html>

Output:

chrome-capture-2023-6-5-(9)

Supported Browser:

You can learn more about CSS Properties from CSS Properties Complete Reference.

CSS is the foundation of webpages and is used for webpage development by styling websites and web apps. You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.

Article Tags :