1. Computing

Discuss in my forum

Jennifer Kyrnin

Poll: Do you indent your HTML?

By , About.com GuideNovember 12, 2009

Follow me on:

Indenting HTML code makes it easier to read and thus easier to maintain later. But some people feel that adding indents can increase the size of pages by adding in white space that isn't used on the page. Personally, I feel that it's important to have some indenting, so that the HTML is easier to read, but putting in a 4-space indent for every nested tag is a bit of overkill as well.

Comments
November 12, 2009 at 10:16 am
(1) plaster says:

The code should be indented, otherwise it’s a pain to maintain. But the production code doesn’t have to be the same as development code!
A deployment of a website could be a process that automatically strips all “unnecessary” whitespace, thus reducing the size of pages.

November 12, 2009 at 4:43 pm
(2) Alexander says:

I agree with the previous commenter, it’s a very good idea to keep an editing version of your textual resources, and to minify them for live use.

I would recommend to gzip and to set your cache/expiration headers, which is a lot more important to me than just a few spaces and tabs (and here we’re talking only about textual files).

Google even advertises sorting your markup alphabetically and quoting consistently to maximize the results of the gzip compression, but I suppose this is practical mostly for high traffic websites, where every octet counts.

November 12, 2009 at 6:41 pm
(3) Rogorm says:

I thought I was the last person still writing HTML! The editors that most people use add a lot more redundancy and superfluous code than a few spaces, so I don’t even give it a thought.

Notepad creates the cleanest code!

November 17, 2009 at 5:54 am
(4) Petculescu George says:

If I use an editor, it indent for me automatically. If I use Notepad++, I consider that a newline between important tags and sections of code is enough, because syntax highlighting will help me.

November 17, 2009 at 4:17 pm
(5) BobR says:

What I do, especially with large pages, is to have all the spaces removed from the page by using the compact format (or at least go to Plain [left justified]) before uploading and then when I need to edit it, switch back to hierarchical again.

November 17, 2009 at 8:14 pm
(6) Richard Hall says:

For a code review, if the HTML was not indented OR not commented OR it did not validate 100%, I would reject it outright.

I indent the code I write for my own use! And I use comments. Who knows -what- I’ll remember when I look at it next.

November 18, 2009 at 2:43 am
(7) Ron says:

“Indenting Wastes Space …”
yah right {/heavy sarcasm!}

The same people probably also say
“Comments Waste Space …”
“Long, english-like variable names waste space …”

In my experience there are 2 groups of people who use those “arguments”. First is the “Dinosaurs” (or more accurately, the “Pioneers”) who wrote assembler code in the ’60s and ’70s when Core memory (not RAM, Core) was measured in KB instead of GB. Back when a mainframe costing millions of dollars had (several) orders of magnitude less CPU power, memory and tape (disk) storage than the current PC sitting on your desktop.

The other group is the “self taught experts”. Too bad they really don’t know what they are talking about.

The simple reality of programming today is that CPU’s are so fast that a few spaces on a line a trivial, even if the code is interpreted instead of compiled. But those few spaces per line make a huge difference to developers trying to understand the intent of the code.

Plaster, if you want to avoid problems, your production code MUST be IDENTICAL to your development code (with trivial allowances for location differences etc between dev and prod) which are hopefully handled by the environment rather than explicitly in the code.

Granted, compilers will strip spaces, comments and shorten variables, but compilers have been very thoroughly tested to prove they do not compromise the code. If you do those type of changes “manually” you are open to introducing all sorts of errors.

February 6, 2012 at 2:09 am
(8) Damien Coon says:

Looking forward to reading more. Great blog.Really looking forward to read more. Cool.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>
Top Related Searches poll

©2013 About.com. All rights reserved.