The Wayback Machine - https://web.archive.org/web/20250404115047/https://www.geeksforgeeks.org/css-text-indent-property/
Open In App

CSS text-indent Property

Last Updated : 28 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The text-indent property in CSS is used to define the indentation of the first line in each block of text. It also take negative values. It means if the value is negative then the first line will be indented to the left. 

Syntax:

text-indent: length|initial|inherit; 

Property values:

  • length: It is used to set fixed indentation in terms of px, pt, cm, em etc. The default value of length is 0. 
  • percentage (%): It is used to define the indentation in % as compared to the width of the element. 
  • initial: It is used to set text-indent property to its default value. 

Example: In this example, we are using text-indent: length; property.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        CSS text-indent Property
    </title>

    <!-- CSS text-indent property -->
    <style>
        .sudo {
            text-indent: 70px;
        }

        .geeks {
            text-indent: -5em;
        }

        .gfg {
            text-indent: 40%;
        }
    </style>
</head>

<body>
    <h1 style="">GeeksforGeeks</h1>
    <h2> text-indent Property</h2>

    <h2>text-indent: 70px:</h2>
    <div class="sudo">
        Prepare for the Recruitment drive of product
        based companies like Microsoft, Amazon, Adobe
        etc with a free online placement preparation
        course. The course focuses on various MCQ's
        & Coding question likely to be asked in the
        interviews & make your upcoming placement
        season efficient and successful.
    </div>

    <h2>text-indent: -5em:</h2>
    <div class="geeks">
        Prepare for the Recruitment drive of product
        based companies like Microsoft, Amazon, Adobe
        etc with a free online placement preparation
        course. The course focuses on various MCQ's
        & Coding question likely to be asked in the
        interviews & make your upcoming placement
        season efficient and successful.
    </div>

    <h2>text-indent: 40%:</h2>
    <div class="gfg">
        Prepare for the Recruitment drive of product
        based companies like Microsoft, Amazon, Adobe
        etc with a free online placement preparation
        course. The course focuses on various MCQ's
        & Coding question likely to be asked in the
        interviews & make your upcoming placement
        season efficient and successful.
    </div>

</body>

</html>

Output: 

Example: In this example, we are using text-indent: %; property.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        CSS text-indent Property
    </title>

    <!-- CSS text-indent property -->
    <style>
        .gfg {
            text-indent: 40%;
        }
    </style>
</head>

<body>
    <h1 style="">GeeksforGeeks</h1>
    <h2> text-indent Property</h2>

    <h2>text-indent: 40%:</h2>
    <div class="gfg">
        Prepare for the Recruitment drive of product
        based companies like Microsoft, Amazon, Adobe
        etc with a free online placement preparation
        course. The course focuses on various MCQ's
        & Coding question likely to be asked in the
        interviews & make your upcoming placement
        season efficient and successful.
    </div>

</body>

</html>

Output: 

Example: In this example, we are using text-indent: initial; property.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        CSS text-indent Property
    </title>

    <!-- CSS text-indent property -->
    <style>
        .gfg {
            text-indent: initial;
        }
    </style>
</head>

<body>
    <h1 style="">GeeksforGeeks</h1>
    <h2> text-indent Property</h2>

    <h2>text-indent: initial:</h2>
    <div class="gfg">
        Prepare for the Recruitment drive of product
        based companies like Microsoft, Amazon, Adobe
        etc with a free online placement preparation
        course. The course focuses on various MCQ's
        & Coding question likely to be asked in the
        interviews & make your upcoming placement
        season efficient and successful.
    </div>

</body>

</html>

Output: 

Supported Browsers: The browser supported by CSS text-indent property are listed below:

  • Google Chrome 1.0
  • Edge 12.0
  • Internet Explorer 3.0
  • Firefox 1.0
  • Safari 1.0
  • Opera 3.5

CSS text-indent Property – FAQs

What is the purpose of the text-indent property in CSS?

The text-indent property in CSS is used to define the indentation of the first line of text in a block-level element, such as a paragraph. It is often used for styling paragraphs in articles or documents.

How do I create a 30px indentation for the first line of a paragraph?

To create a 30px indentation for the first line, use: text-indent: 30px;. This moves the first line of the paragraph 30 pixels to the right.

Can text-indent accept negative values?

Yes, text-indent can accept negative values, which will pull the first line of text to the left beyond the start of the block.

Does text-indent apply to all lines of text?

No, text-indent only affects the first line of text within the block element. Subsequent lines are unaffected by this property.

What units can be used with text-indent?

Text-indent can use various units, including pixels (px), em, rem, percentages (%), and other length units to define the indentation.



Next Article

Similar Reads

three90RightbarBannerImg