Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indenting HTML.

Status
Not open for further replies.

butterfm

Programmer
Feb 15, 2002
132
GB
Hi,

Is it normal practice to indent HTML where you have nested tags, for example creating a table inside the cell of another table.
The majority of HTML i've seen is not indented, even when tags are nested, which sometimes makes it difficult to read and easy to forget closing tags.

Is it down to personal preference or is there a good reason why you shouldn't indent.

M.


 
I personally indent because it makes things easier to read. Indenting might bump the file size up a little bit but thats a price I'm prepared to pay.



MrBelfry
 
I indent everything because if I didn't, I wouldn't be able to read it after 72 hours.

If you see messy code, look in the meta tags for the Generator.

So, a good reason to not indent is because it's almost like encrypting your code. [lol]

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Entirely personal preference. Indenting makes it easier for humans to read the code, browsers don't care. If you're using a WYSIWYG editor and never delve into the actual HTML, there's no reason to indent (and your files will be a bit smaller too). If you're a hand coder it makes rather more sense.

To indent (and otherwise tidy up) an HTML file, try running it through .

-- Chris Hunt
Extra Connections Ltd

The real world's OK for a visit, but you wouldn't want to LIVE there!
 
Chris Hunt: If you're using a WYSIWYG editor... and your files will be a bit smaller too.

[rofl]

When I compare the output from any editor I know of to the indented output from my own fingers, my code is always smaller, usually less than half the file size.

You're right about personal preference, though. [smile]

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Edward is absolutely correct... hand-coding is 50% smaller (at least!) than (most) WSIWYG editors' output (puh-leaze).

Indented HTML is the only way to go (IMHO)...
 
Wow. Um, I ran one of my pages through HTML Tidy and it came out bigger!

The most significant difference is that it chose to add a bunch of line breaks where I don't have 'em. I even set the line width breakpoint at 0, which meant that it shouldn't have done that.

Hm, a couple of blank lines (I put in to separate pieces of code) were sucked up. Yeah, I understand it, but it still makes for a slightly less organized look.

Well, I'll stick with my cranky ol' hand-coding.

I know, I'll make up a nifty looking icon that you can use if your page is "hand-crafted", just like the W3C icons. hee-hee!

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Wow. Um, I ran one of my pages through HTML Tidy and it came out bigger![/i]

Possibly. Did it also run faster (far more important than a few more bytes over the line ;)).

Ever more HTML you see that's not indented is automatically generated by webservers using some for of serverside processing (CGI, ASP, JSP, Servlets, CFM, the list goes on).
As no human ever maintains that code there's little reason for the programmer to meticuously make sure that it's properly indented (even if it's possible).
 
Using ASP, it IS possible to keep your HTML output (at least reasonably) indented.

...it just takes attention to detail... something I think is largely lost on WYSIWYG coders.

BTW: I know that's a personal bias, and is probably inappropriate... but I still think its true. ;-)
 
All of my scripts produce politely indented code because they are acting as representatives of me.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top