The Wayback Machine - https://web.archive.org/web/20241008162137/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
Save
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.



Previous Article
Next Article

Similar Reads

Which property is used to indent the text of a paragraph ?
In this article, we will see the property that is used to indent the text of a paragraph. The text-indent property in CSS is used to define the indentation of the first line in each block of text. It also takes negative values. It means if the value is negative then the first line will be indented to the left. Syntax: text-indent: length|initial|in
2 min read
How to indent text in HTML by using CSS ?
We will discuss various methods to indent text in an HTML document. Text indentation sets the length of empty white space before lines of text in a block, typically marking the beginning of a paragraph. Here are some common approaches for text indentation: Table of Content Using the margin-left property: Using the text-indent property: Using paddin
3 min read
How to set indent the second line of paragraph using CSS ?
There are several methods to indent the second line of the paragraph that can be achieved in many ways. Some of the methods to achieve this are described below with proper code and output. Now some styling can be done using CSS in various ways to indent the second line as per need. Note: By default, when lines wrap, they just start right below wher
3 min read
How to Style the Text using text-decoration Property in CSS ?
The text-decoration property in CSS is used to style the decoration of text, such as underlining, overlining, line-through, and blink effects. It is a versatile property that can enhance the visual appearance of text. Syntax/* Example of using the text-decoration property */ .element { text-decoration: [value]; }The text-decoration Property ValuesT
1 min read
How to create long shadow of text without using text-shadow in HTML and CSS ?
Shadows are really a nice way to give depth and 3-D look to any text. Generally, we use text-shadow to give shadow to the text but this shadow is short and to create long shadow (shadow in which text is visible like that of reflection) we have to use before selector and skew function. Approach: The approach is to use a skew to create tilted text fi
2 min read
Text Animation with changing the color of the text using HTML and CSS
Text animation is the creation of beautiful and colorful letters, words, and paragraphs with a decorative movable effect. The movement can be seen in some fashion within the area or across the screen following some regular pattern. The @keyframes in CSS allows defining a series of animations at specific points during an animation sequence. In this
2 min read
How to use text overflow property in CSS ?
In this article, we will see how to set text overflow property in CSS. The text-overflow property is used to specify that some text has overflown and hidden from view from the user. The text-overflow property only affects content that is overflowing a block container element. Syntax: text-overflow: clip| ellipsis Property Value: clip: Text is clipp
2 min read
CSS | text-orientation Property
The text-orientation property in CSS is used to set the orientation of the character in a line. This property is useful in vertical scriptings, like creating vertical table headers, defining the row's names, etc. Syntax: text-orientation: mixed|upright|sideways; Attribute: mixed: This value is used to rotate the character of text into 90 degree clo
2 min read
CSS | text-decoration-skip-ink Property
The text-decoration-skip-ink property is used to specify how the underlines and overlines are rendered when they pass through the characters or glyphs. Syntax: text-decoration-skip-ink: auto | none Property Values: auto: This value is used to specify to skip the underlines and overlines that pass through a character. It is the default value.none: T
2 min read
Differences between HTML <center> Tag and CSS "text-align: center;" Property
If you are designing a simple web page, then not much difference is noticeable, but it is very necessary to understand the basic differences between these two. Since we are only concerned with the text, these elements do not have separate meanings.HTML <center> tag: The <center> tag in HTML is used to set to align of text into the cente
3 min read
Which property is used to underline, overline, and strikethrough text using CSS ?
In this article, we will see the property that can be used to underline, overline, and strikethrough the text. text-decoration: The text-decoration property is used to add decoration to the text. This styling property is used to add decorations like underline, overline, and strikethrough. This property is also used as a shorthand property for the b
2 min read
CSS text-underline-offset Property
In this article, we'll discuss the text-underline-offset property in CSS. It is used with an underlined text but it's not part of it. To set the offset distance of the underline from its original position. By default, it is set to auto, but we may increase it by specifying the length or percentage. If any element contains multiple text-decoration l
2 min read
CSS text-emphasis Property
In this article, we will discuss text-emphasis property in CSS. It is a short-hand property for text-emphasis-style and text-emphasis-color. It applies emphasis properties to characters (except spaces and control characters). Syntax: text-emphasis: text-emphasis-style text-emphasis-color; Properties: text-emphasis-style: It defines the shape of the
1 min read
CSS text-decoration-thickness Property
In this article, we will discuss the text-decoration-thickness property in CSS. This property sets the width of the stroke of the decorated line below, above, or through the text. The different values that this option can take are as follows: auto: The thickness of the text-decoration line depends on the browser.font-file: Some font files include t
4 min read
CSS text-emphasis-position Property
The text-emphasis-position property in CSS is used to define the position of the emphasis marks like dots, circles, and lines applied to text. The line height will increases if there isn't enough space for emphasis marks. These marks are used to draw attention to specific text. The emphasis marks are vertically centered with the text by default, bu
3 min read
How to use text-align property inside a table in CSS ?
Text align is a CSS (Cascading Style Sheets) property that is used to specify the horizontal alignment of text within an HTML element. It is commonly used to align text within a block-level element such as a paragraph, heading, or table cell. The "text-align" property accepts several values. left: It aligns the text to the left edge of the element.
5 min read
CSS text-emphasis-color Property
The text-emphasis-color CSS property allows us to set the color of the emphasis marks that you can create using the CSS text-emphasis property. The text-emphasis property applies emphasis marks like dots, circles, and lines to the text. Syntax: Below is the syntax for applying the color to the emphasis marks. text-emphasis-color: <color>Prope
2 min read
CSS text-underline-position Property
The text-underline-position CSS property specifies the position of an underline on text. It allows control over whether the underline is placed below, above, or at a custom offset from the text. This property enhances text readability and aesthetics, especially in complex layouts. Syntax: The following is the syntax for the text-underline-position
3 min read
CSS text-align-last Property
The text-align-last property in CSS is used to set the alignment of the last line in a block or paragraph, just before the line break. This property can be applied to control how the final line of text is aligned within its containing element, whether it ends naturally or due to the use of a <br> tag. By leveraging the text-align-last propert
7 min read
How to Center an Image using text-align Property in CSS ?
Aligning an image horizontally within a container can sometimes be challenging. In this article, we will explore how to center an image using the text-align property in CSS. Understanding the text-align PropertyThe text-align property in CSS is used to specify the horizontal alignment of text within an element. It can also be used to center inline
2 min read
CSS text-decoration Property
In CSS, the text-decoration property is used to control the decoration of text, such as underlines, overlines, line-throughs, and blink effects. This property accepts values like none, underline, overline, and line-through, and inherits to style text decorations accordingly. Understanding the text-decoration property and its shorthand variations al
3 min read
CSS text-decoration-color Property
The CSS text-decoration-color property is used to specify the color of text decorations, including overlines, underlines, and line-throughs. Syntaxtext-decoration-color: color | initial | inherit;Property ValuesValues Descriptions color Sets the color of the text-decoration initial Sets the property to its default value inherit Inherits the propert
2 min read
CSS text-decoration-line Property
The text-decoration-line property is used to specify the type of text decoration, such as underline, overline, or line-through. It can be combined with other text decoration properties to create complex effects. Syntax: text-decoration-line: none | underline | overline | line-through | initial | inherit;The text-decoration property is a shorthand p
4 min read
CSS text-align Property
The text-align property in CSS controls the horizontal alignment of inline content (such as text) and inline-block elements within their containing block-level element. #content-iframe { width: 100%; height:400px;} @media (min-width: 1785px) {.article--viewer .a-wrapper .content .text #content-iframe {max-width: 100%; min-height: 440px; height: aut
4 min read
CSS text-decoration-style Property
The CSS text-decoration-style property sets the style of text decoration, such as solid, double, dotted, dashed, or wavy lines. It works with text-decoration-line and text-decoration-color to customize text appearance, enhancing visual presentation and user experience on web pages. Syntaxtext-decoration-style: solid|double|dotted|dashed|wavy|initia
6 min read
CSS text-justify Property
The text-justify property specifies the method for justifying text when text-align is set to justify. It manages the spacing between words or characters to ensure the text spans the full line width, with options like auto, inter-word, inter-character, and none for improved text formatting and readability. Syntaxtext-justify: auto|inter-word|inter-c
4 min read
CSS text-overflow Property
The text-overflow property in CSS is your go-to feature when dealing with overflowing and hidden text. It works in tandem with the white-space property set to nowrap and the overflow property set to hidden. The overflowing content can be clipped, display an ellipsis (‘â€Ķ’), or display a custom string. Syntax: text-overflow: clip|string|ellipsis|init
4 min read
CSS text-shadow Property
The CSS text-shadow property adds shadows to text for depth and emphasis. It accepts values for horizontal and vertical shadow positions, blur radius, and shadow color. The default is no shadow is none. Syntax text-shadow: h-shadow v-shadow blur-radius color | none | initial | inherit; Property values Here are the property values for the text-shado
4 min read
CSS text-transform Property
The text-transform property in CSS is used to control the capitalization of text. It allows you to transform text to uppercase, lowercase, or capitalize the first letter of each word. Syntaxtext-transform: none| capitalize | uppercase | lowercase |initial | inherit; Property ValuesHere are the property values for the text-transform CSS property: Va
4 min read
How to get text inside Text component onPress in ReactJS ?
In this article, we will learn "How to get the text inside Text component onPress in ReactJS?". Problem Statement: Sometimes in an application, it is required to get the text inside certain components, in order to reuse the components again & again just by changing the text value. Approach: We will set the property inside the component's tag to
4 min read