Should HTML be Indented?[Answered]

Advertisement

Yes, HTML should be indented uniformly because it makes HTML code more readable. This results in an easier to maintain code compared to HTML code without indentations.

How to Indent HTML Code

There are three common methods used to indent HTML code: two spaces, four spaces and tab space.

All the 3 methods works well. However, Google’s HTML CSS guidelines suggests use of two spaces indentation.

Which ever indentation style you choose, use it across, across the whole project. This will result in a well structured project with less confusion.

Must HTML be indented

No. HTML will still work without indentation. However, editing and maintaining unindented HTML code is a nightmare. Please indent your HTML and you will thank yourself in the future.

Is there a reason to remove indentation in HTML?

One reason to remove indentation is when you want to make your HTML code unreadable. It is called code obfuscation. You are making it hard to read for humans but browsers can still interprete it correctly.

A second reason might be when you want to reduce the size of HTML file. This is called minification.

author's bio photo

Hi there! I am Avic Ndugu.

I have published 100+ blog posts on HTML, CSS, Javascript, React and other related topics. When I am not writing, I enjoy reading, hiking and listening to podcasts.