Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS text-indent Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 29 - Views
⏳ 4 mins
💬 1 Comment
CSS text-indent Property

Photo Credit to CodeToFun

🙋 Introduction

The text-indent property in CSS is used to specify the indentation of the first line of text in a block-level element.

This property allows you to create a visual distinction at the beginning of a paragraph or other block of text, enhancing the readability and visual appeal of your content.

💡 Syntax

The syntax for the text-indent property is simple and can be applied to any block-level element containing text.

Syntax
Copied
Copy To Clipboard
element {
  text-indent: length | percentage;
}

🎛️ Default Value

The default value of the text-indent property is 0, which means no indentation.

🏠 Property Values

ValueDescription
lengthSpecifies a fixed length for the indentation. For example, text-indent: 20px; indents the first line by 20 pixels.
percentageSpecifies an indentation as a percentage of the containing block's width. For example, text-indent: 5%; indents the first line by 5% of the container's width.
negative valueNegative values are also allowed, which will cause the first line to be indented to the left.

📄 Example

In this example, we'll indent the first line of a paragraph by 50 pixels.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS text-indent Example</title>
  <style>
    p {
      text-indent: 50px;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Custom Text Indentation</h1>
  <p>
    This is an example paragraph. The first line of this paragraph is indented by 50 pixels. The text-indent property can be used to create a visual separation between paragraphs, making the content easier to read.
  </p>
</body>
</html>

🖥️ Browser Compatibility

The text-indent property is widely supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is also supported in older versions of these browsers, making it a reliable choice for cross-browser compatibility.

🎉 Conclusion

The text-indent property is a useful tool for web developers looking to enhance the readability and visual appeal of their text content.

By customizing the indentation of the first line of text, you can create a more polished and professional look for your web pages. Experiment with different values and see how this property can improve the presentation of your text.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy