What is indentation in html

HTML Indent

Javascript Course - Mastering the Fundamentals

Indentation is the blank space between the margin and the beginning of a line of text. Text indentation improves readability by setting the length of empty white space before lines of text in a block to mark the beginning of a paragraph. This article is a guide on how you can indent content on your webpage and why it is important to do so.

The following image contains two pieces of text. It can be seen that the second one looks more organized and readable because of proper indentations.

before-and-after-applying-of-indent

Pre-requisites

What are We Creating?

In this article, you shall learn to indent content in HTML. You shall use the following two properties:

  • margin-left — To indent an entire block of text.
  • text-indent — To indent only the first line of text.

indent-content

How to Indent in HTML?

Example 1: Using the margin-left property

The margin-left property adds a margin to the left of an element. The required amount of indentation is applied to the whole block of text. The amount of space can be specified using absolute or relative values.

It is possible to achieve text indentation using an inline style within HTML. In the following example using margin-left , the entire text in the paragraph tag is indented 25 pixels from the left.

output-margin-left

Example 2: Using the Text-indent Property

The text-indent property adds space to the left of the first line of text in a paragraph. The required amount for HTML indent is specified using absolute or relative values.

It is possible to achieve text indentation using an inline style within HTML. In the following example using text-indent , the first line of the paragraph tag is indented 25 pixels from the left.

text-indent-output

Note: The CSS properties of text-indent and margin-left have the same name as their HTML inline properties. So, in CSS the properties and their values are mentioned within the desired selector. Use the style tag in the HTML head or an external stylesheet to include the CSS code.

Commonly Used Examples of Indentation in HTML

Unordered lists

The li elements nested inside their parent ul , are indented to the right by two spaces.

unordered-list-output2

Ordered lists

The li elements nested inside their parent ol , are indented to the right by two spaces.

ordered-list-output2

Why is Indentation Important?

Indentation improves readability. Maintaining proper indentation is a good practice as this makes text readable and enhances user experience.

Читайте также:  Html css style name

It is clearly visible how adding indentation makes your document look more organized.

difference-by-adding-indentation

Conclusion

  • Indentation is the blank space between the margin and the beginning of a line in a text block.
  • HTML text-indent property helps to set the desired value for indentation.
  • HTML indent is observed in li items under ol and ul .
  • The text-indent property is applied using the selector rule in CSS and as an inline style in HTML.
  • The text-indentation value can be absolute like pixels (px) or relative like em, rem, or % of the overall element width.
  • margin-left indents the entire text block, whereas text-indent indents the first line of the paragraph.

Источник

How to Indent in HTML

As we all know that HTML documents are very similar to MS Word documents but the only difference is HTML is used to create web pages while MS word is used to create simple document files. Have you ever wondered how we format text just like ms word in HTML? In MSword, we indent text and paragraphs but what if we want to indent a paragraph and text in HTML?

The HTML indentation of the code tags is performed manually whereas the HTML content can be indented by using various CSS properties. This post aims to indent text in HTML and serves the following outcomes:

How to indent text in HTML

Indentation is the process of defining the spaces from the left or right of the paragraph. In HTML, there are three approaches to indent in HTML: tag, , and .

All the above approaches have different functionalities and syntax so let’s dig into them and explore each approach one by one.

How to indent in HTML using the tag

In HTML, we can use the tag to indent because the tag displays the text as it was written in the source code.

HTML Indentation < / h1 >

This paragraph is written to apply indentation on it. In Html
indentation is something that is not needed because browsers automatically
removes the extra white spaces but if you want to make your text look good
for the reader then indentation is useful for you.
< / pre >
< / div >
< / body >

In the above example we use tag and it is wrapped around some text.

It is observed from the output that the paragraph is displayed as it was written in the source code.

How to indent in HTML using the margin-left property

We can also use the CSS margin-left property to indent the text in HTML. The following example will help you to understand better.

HTML Indentation < / h1 >

This paragraph is written to apply indentation on it. In Html indentation is something that is not needed because browsers automatically removes the extra white spaces but if you want to make your text look good
for the reader then indentation is useful for you.
< / p >
< / div >
< / body >

In the above example we use CSS margin-left property on tag to indent in HTML. The value of the margin-left property is set to 50px.

Читайте также:  What is text css in html

This output shows that the margin-left property adds space to the left of the paragraph and moves the whole paragraph to the right.

How to indent in HTML using the text indent property

The text-indent property adds space on the left of the first line of a paragraph to indent in HTML. The following example will help you to understand better.

HTML Indentation < / h1 >

This paragraph is written to apply indentation on it. In Html indentation is something that is not needed because browsers automatically removes the extra white spaces but if you want to make your text look good
for the reader then indentation is useful for you.
< / p >
< / div >
< / body >

In the above example we use CSS text-indent property on tag in order to indent in Html.

This output shows that the text-indent property adds space to the left of the first line of the paragraph in order to indent the paragraph.

Conclusion

In HTML, indentation is done with the help of text-indent property, tag and margin-left property.his article aims to demonstrate various methods to indent in HTML Indentation enhances readability of the content. However, it is useless for HTMLbecause browsers ignore white spaces and line breaks if you do not use the indentation techniques in HTML.

Источник

CSS and HTML Indent: How to Indent Texts When Coding & Why Is It Important?

Do you want to indent text on your web page? HTML indent is a code that allows you to add space. How to do it, and why is it important? In this article, we will cover indentation within HTML. Read on to learn more.

HTML Indent

What Is HTML Indent?

Indentation is especially important in HTML because it can help you understand the structure of a document. HTML indent is a process of adding white space before the start of HTML elements to increase the readability of HTML code. By default, HTML browsers do not display anything for HTML indent, but they will recognize it as valid HTML code. Margin-left and margin-right are the two main ways to create HTML indentation.

This way, the parent-child relationship of HTML elements is more obvious. For example, let’s say you have the following HTML code:

If you don’t indent the code, it can be difficult to see which HTML elements are nested inside other HTML elements. But if you indent the code, the structure becomes much clearer. For example, the following is the unindented code:

In this case, the code is difficult to read because the HTML elements are not properly aligned.

What Is Text-Indent Property in HTML?

The text-indent property is used to specify the amount of space that should be inserted before the start of a paragraph. The value can be either a length or a percentage. If the value is a length, the paragraph will be indented by that much space. If the value is a percentage, the paragraph will be indented by that percentage of the width of the containing element.

Why Is HTML Indentation Important?

HTML indent is important because it can make your HTML code more readable. When you indent your HTML code, it is easier to see the structure of the document. This can be especially helpful when you are working with large HTML documents.

Читайте также:  Тег FORM

In addition to making your HTML code more readable, HTML indentation can also improve the usability of a web page. Indentation can help users understand the hierarchy of a web page and quickly find the information they are looking for.

Finally, HTML indent can make it easier to spot errors in your HTML code. When your HTML code is properly indented, it is easier to see when there are missing or misplaced elements.

How to Indent Texts?

There are two ways to indent HTML code:

To use the tab character, simply press the tab key on your keyboard. The number of characters you use is up to you, but it is generally recommended to use two spaces for HTML indentation.

To use spaces, simply type a space character before or after an HTML element. The number of characters you use is up to you, but it is generally recommended to use four spaces for HTML indentation.

CSS and Text Indentation

In addition to HTML, you can also use CSS to indent HTML code. The indentation property is used to specify the amount of space that should be added before or after an HTML element.

The indentation property can be specified using either the px (pixels) or em (em) units. For example, you could use the following CSS code to add four pixels of space before an HTML element.

What Is a Hanging Indent?

A hanging indent is an HTML formatting technique where the first line of a paragraph is not indented, but subsequent lines are. This technique is not recommended for creating indentation, but can be useful when using microdata.

To create a hanging indent, you will need to use the HTML tag.

Indent Your Code – How to Do It Effectively?

HTML indentation is a great way to make your HTML code more readable. However, there are a few things you should keep in mind when using HTML indentation:

  1. Use a consistent indentation style: When indenting HTML code, it is important to use a consistent style. This means using the same number of characters for each level of indentation, and using the same character (e.g. space or tab) for each level of indentation.
  2. Don’t overdo it: While HTML indentation can improve readability, too much indentation can actually make code more difficult to read. When in doubt, less is more.
  3. Use a code editor: A good code editor will automatically indent HTML code for you. This can be a huge time saver, and can help to ensure that your HTML code is properly indented.
  4. Validate your HTML: Before publishing your HTML code, be sure to validate it using an HTML validator. This will help to ensure that your HTML code is well-formed and free of any errors.

A full-time programmer who specializes in HTML and JavaScript. William originally wanted to become a teacher, so he’s very eager to share his knowledge. He spends his free time with his two wonderful childern and his wife Meg.

Источник

Оцените статью