Do you need to indent when writing HTML code?

Updated: 08/31/2020 by Computer Hope
Indented code
Note

This page contains information on indenting HTML code and not how to indent text on a web page. For help with indenting text with HTML, see: How to indent or tab text on a web page or in HTML.

No. HTML code does not need to be indented, and all browsers and search engines ignore indentation and extra spacing. However, for any human reader, it's a good idea to indent your text because it makes the code easier to scan and read. If you are editing your website content in a text editor, indenting your code correctly makes it easier to read. If you only use a WYSIWYG (What You See Is What You Get) editor to modify your web page indentation may not be as important.

Tip

If you are using an HTML editor, all editors allow you to clean up or format your HTML. Using this feature helps clean up the code of any web page that is hard to read.

How to clean up HTML code

Adobe Dreamweaver

Click Commands and then Apply Source Formatting.

Microsoft Expression Web

In the HTML view right-click anywhere and choose Reformat HTML.

I want to indent, how should I indent my source?

There is no standard or rule on how to indent your code. Some people indent their code with one or more space, and others indent their code with the Tab. Regardless of how you decide to indent your code, the important thing is to make sure anyone editing the file indents lines the same way.

Why do some pages have no indentation?

Today, many pages use CMS (Content Management System) or other scripts to generate the HTML code that may not be indenting the code when created. Also, some websites may compact or compress their HTML code to help reduce the size of the file to reduce bandwidth and increase the download speed.