html

CSS List Indent

A cascading style sheet is a language that is used to enhance the current content created through the HTML language. Both languages work together to form a web page. HTML is concerned with creating and CSS designs all the elements of HTML. HTML has many contents that help in creating a web page. In all of them, the text is the basic content that is used by every webpage to display any sort of information. One of the contents that are used to display text is lists. In this article, we will talk about lists that have text-indent property and how this property works on the list.

CSS lists:

The vertical demonstration of HTML data either in an ordered or unordered form is represented through a special HTML content known as lists. The content written inside the list is mentioned with the bullets. Eventually, lists are divided into two main types: an ordered and an unordered list. If we want to give numbering to the data, it is an ordered list <ol>. The data with any type of bullet without numbers is an unordered list <ul>. These two <ul> and <ol> are only responsible for displaying the type of list. The simple syntax that is used to create a list:

<ul>
<li> data </li>
</ul>

It is a snippet of a webpage having an unordered list. You can see that all the data is represented forming a small list with bullets that shows it is an unordered list.

CSS indent property and list:

This is the property applied to the HTML content, mainly on text. It is used to displace the text from its original point to a specific place. This property is used to seek the user’s attention on specific content. You may have seen some websites with paragraph starting from a distance compared to the heading, making it more prominent in front of the viewer. The syntax used to apply this property is simple. We only add a length parameter to this property either in pixels or with percentage units.

Text-indent: length;

Example 1:
This example deals with displaying a list of items that are generated like a normal list and also a second list that contains items that are displaced from their original position. Let us see the HTML body code to create a list.
A heading is added to the webpage by using <h3> heading tag. Then, we used an ordered list.

 <ol>
<li> item</li>
<li> item</li>
</ol>

This ordered list will create default numbering digits with the items in list tags. Another heading is declared followed by an ordered list again. A class of CSS is declared inside the second <ol>.

<ol class= "custom indent">

This is just the name of the CSS class, it is declared in the head section of the HTML code. Whenever this class name is used in any tag, all the filters or effects mentioned in this class in the style statement are applied.

Inside the head, a title is given to the page. A style tag is used to apply the effects. This type of styling is known as internal CSS.

<style>
.customIndent {
Padding-left: 7em;
} </style>

A class customIndent is declared. Inside the class description, we do not have used the text-indent property directly. In fact, we can indent the list items by using the padding property in any dimension. So, as we want the list to be displayed with its content in the right direction, we will use the padding-left property to indent the text from the left position towards the right direction.

The padding property is the distance of the HTML content from the specified border of either the outer content or the HTML page.

Close all the tags on the head. Save the file with the html extension to create a webpage in the browser whenever this file is opened with a browser. And when we open it in the text editor, it will display the code only.

You will see that a simple list is displayed without any indent effect because we have not applied the CSS class name to it. But the second list with a custom indent is dragged towards the right position. This is because of the padding property.

Example 2:
In this example, we are using the same example but with different CSS properties to indent the text in the list. Inside the style tag, the CSS class has a margin property. This margin is the distance of the content from the border of the page. In this case, we have HTML text, so the text inside the list will be moved according to the value.

.customIndent {
Margin-left: -15px; }

In this example, we want the list to be with the left margin. So, we took the margin value towards the left side. The value is taken in a negative sign to go backward. If the distance has been taken with a positive sign, then the list will be on the right side of the page.

This style is again applied to the second list we created with a custom index class.

Now, we will execute the webpage to see the result. You will see that the ordered list is stuck on the left-most side of the page.

Example 3:
This example deals with the use of an unordered list on the web page. Inside the list, we have taken 4 rows of items. In this example, we will not use CSS styling through a class. We will not apply the indent text property to the whole list. The single line in the list will be effected through the text-indent property. This will be done by using another CSS property that is a ‘first-of-type’ property.

This property deals with selecting the very first occurrence of an item in all the same HTML contents. For instance, this property will affect only the first row of the line, without mentioning the name of any list or the class inside the tag.

While writing the style statement in the head section of the code, we will use the <li> as we want to apply the effect on the li.

Li: first-of-type {
Text-indent: 50px;
List-style-type: star;
}

The first item will be moved towards the right with a specified distance mentioned above. And also, we have given a number to that item for the discrimination.

On the execution, you will observe that the first item of the list is displaced in the right direction and the bullet is also referred to as a decimal number.

Conclusion

This article aims to describe the purpose and use of the indent property in the list of HTML content. We start with a brief explanation of the lists and their types. The indent property can be applied to any of the list types. After that, we have used three basic examples including the padding effect, margin, and the text indent affect property by using the first-of-type CSS property. All these examples show the indentation of the whole list and a single row of the list as well.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.