Indentation style

G

Gunter Ganscher

I am trying to search Google for information about coding standards with
regards HTML and indentation, but all I can seem to find is coding
standards documents for programming languages that happen to be HTML
files, arguments about tabs versus spaces, and other things totally
irrelevant to my question. What is the common way of indenting HTML?
Should it be indented at all?

Gunter
 
L

Lauri Raittila

I am trying to search Google for information about coding standards with
regards HTML and indentation,

There is no standard.
Should it be indented at all?

If you need to indent html, you are usually doing something wrong. There
is shitloads of exeptions (big/nested/complicated tables¹), and of course
it is matter of taste too. Personally, I don't like indenting on html, it
makes less markup available on screenful.

Identation makes sence, if you have complicated structure, and lots of
code compared to content. Both are not usually signs of good html.

[1] Yes, all those can be correct way to mark up content.
 
N

Nick Theodorakis

I am trying to search Google for information about coding standards with
regards HTML and indentation, but all I can seem to find is coding
standards documents for programming languages that happen to be HTML
files, arguments about tabs versus spaces, and other things totally
irrelevant to my question. What is the common way of indenting HTML?
Should it be indented at all?

It's only for the convenience of the coder or the ones reading the
code. Indent it (or not) as you find comfortable.

Nick
 
R

Richard

I am trying to search Google for information about coding standards
with
regards HTML and indentation, but all I can seem to find is coding
standards documents for programming languages that happen to be HTML
files, arguments about tabs versus spaces, and other things totally
irrelevant to my question. What is the common way of indenting HTML?
Should it be indented at all?

During the actual coding?
That's personal prefernce actually.
I generally indent 2 or 3 spaces just to help show where things seperate.
Indent for nested items, leave the rest alone.
For instance
<div>
...<div>
.....<div>xx</div>
...</div>
</div>
 
G

Gunter Ganscher

Nick said:
It's only for the convenience of the coder or the ones reading the
code. Indent it (or not) as you find comfortable.

Isn't that the usual reason for coding standards? If indentation is
uncomfortable for me, but is comfortable for others, shouldn't I indent
anyway?

Gunter
 
G

Gunter Ganscher

Lauri said:
There is no standard.

I find this odd. Almost every computer language I know has at least one
or two published coding standards.
If you need to indent html, you are usually doing something wrong. There
is shitloads of exeptions (big/nested/complicated tables¹), and of course
it is matter of taste too. Personally, I don't like indenting on html, it
makes less markup available on screenful.

I don't like it so much either, but what I really hate is when HTML is
indented, but not consistently. Often, when pieces of HTML are pasted
together, the indentation is totally messed up, and nobody bothers to
fix it. It can be very misleading. This is why I think it should be
standardized. If we all indented consistently, this problem would go
away. If we all agreed to not indent at all, the problem would also go away.
Identation makes sence, if you have complicated structure, and lots of
code compared to content. Both are not usually signs of good html.

I think it depends.

Gunter
 
G

Gunter Ganscher

Richard said:
During the actual coding?
That's personal prefernce actually.
I generally indent 2 or 3 spaces just to help show where things seperate.
Indent for nested items, leave the rest alone.
For instance
<div>
..<div>
....<div>xx</div>
..</div>
</div>

Right, but do you indent all tags, or just certain ones? Where do you
draw the line? Certainly, some tags are meant to be used inline, like
<b>, but other tags are not inline, and people don't seem to want to
indent them anyway, like <html>.

And that brings up another question. Does anyone really use <tbody> in
every table? It's part of the standard, and even if you leave it out, at
least in Mozilla, one gets inserted into the DOM, and you have to be
aware of this if you use JavaScript to manipulate the document. But
<tbody> seems utterly pointless, and adds another level of indentation,
if you indent. Especially when you have nested tables, this can really
push you out pretty far. What's the point?

Gunter
 
J

Jukka K. Korpela

Gunter Ganscher said:
If indentation is
uncomfortable for me, but is comfortable for others, shouldn't I indent
anyway?

Maybe not.

HTML is somewhat peculiar and different from most programming languages
in indentation, because white space may be significant, at least in
practice. This may force you to use unnatural formatting for HTML source.

For example,

<td>
<img src="foo" alt="bar">
</td>

is different from

<td>
<img src="foo" alt="bar">
</td>

in the sense that the former contains space characters before and after the
<img> element. And in practice, browsers may render those characters some
way, which is probably not what you want. (It's debatable what the
situation really means by the specs, but in any case the <td> element here
contains some character data content in addition to the <img> element. The
question is whether whitespace should be ignored in such a situation; the
specifications don't take a position on this.)

Moreover, although the latter is _by the specs_ equivalent to

<td><img src="foo" alt="bar"></td>

due to special rules in SGML about line breaks immediately after or before
a tag, browsers widely violate this and treat those line breaks as
equivalent to spaces, causing the same problem as above.

Thus, authors often need to put stuff on one line to avoid "white space
bugs". If the line would be excessively long, they may decide to use a line
break inside a tag, as in

<td><img src="foo"
alt="bar"></td>

where the line break is harmless.

As a separate issue, an attribute value should be on one line to avoid
varying oddities in browsers (and to follow newest recommendations).
Since an attribute value (especially an alt or a title attribute but also
many attribute values that are URLs) can be fairly long, this tends to mess
up any pretty printing of HTML source.
 
D

David Dorward

Gunter said:
And that brings up another question. Does anyone really use <tbody> in
every table?

Anybody who uses HTML 4.01 does - the start and end tags are optional so it
gets inserted by implication.

Limitations in XML mean that the spec was changed to allow <tr> elements to
be children of said:
But
<tbody> seems utterly pointless, and adds another level of indentation,
if you indent. Especially when you have nested tables, this can really
push you out pretty far. What's the point?

What's the point of nested tables? Generally people who can't be bothered to
learn CSS properly, or who has a weird need to have the site looking
identical for the amazingly tiny proportion of Netscape 4.x users.

As for tbody, its rather useful to be able to style the <thead> and <tbody>
differently - and its rather nice to divide tables into logical sections
with (and then style a nice thick border around each section).
 
L

Lauri Raittila

what I really hate is when HTML is indented, but not consistently.

easy fix: s/\t//g
It can be very misleading. This is why I think it should be standardized.

Well, 99.99% of html is invalid, and more is incorrect. How the hell you
think people that can't write correct html would write it in correct way?
 
A

Adrienne

Gazing into my crystal ball I observed Gunter Ganscher
I am trying to search Google for information about coding standards with
regards HTML and indentation, but all I can seem to find is coding
standards documents for programming languages that happen to be HTML
files, arguments about tabs versus spaces, and other things totally
irrelevant to my question. What is the common way of indenting HTML?
Should it be indented at all?

Gunter

I usually only indent major containers, eg:

<div id="container">
<div id="content">
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<table summary="a table">
<caption>Table</caption>
<tr>
<td>A Cell</td>
</tr>
</table>
</div>
</div>

I also write a lot of server side code, and I indent if conditions,
for/while loops, switch case, etc. In that case indenting makes reading
the code a little easier.
 
A

Andy Dingley

It was somewhere outside Barstow when Gunter Ganscher
I am trying to search Google for information about coding standards with
regards HTML and indentation,

HTML really doesn't care about this (*)

So use whatever your personal editor does by default, when you hit
auto-wrap. Anything else is just too annoying to work with. Make the
tab display settings such that you can see it.

Should your editor be broken enough to actually kill something
important in HTML when it wraps, switch to a less-broken editor.


(*) Naturally IE is a little broken here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top