CSS Properties
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.
element {
text-indent: length | percentage;
}
🎛️ Default Value
The default value of the text-indent
property is 0, which means no indentation.
🏠 Property Values
Value | Description |
---|---|
length | Specifies a fixed length for the indentation. For example, text-indent: 20px; indents the first line by 20 pixels. |
percentage | Specifies 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 value | Negative 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.
<!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:
Author
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
If you have any doubts regarding this article (CSS text-indent Property), please comment here. I will help you immediately.