Indentation style

Discussion in 'HTML' started by Gunter Ganscher, Feb 26, 2005.

  1. 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
     
    Gunter Ganscher, Feb 26, 2005
    #1
    1. Advertising

  2. in alt.html, Gunter Ganscher wrote:
    > 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.

    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
     
    Lauri Raittila, Feb 27, 2005
    #2
    1. Advertising

  3. On Sat, 26 Feb 2005 13:40:15 -0700, Gunter Ganscher
    <> wrote:

    >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

    --
    Nick Theodorakis

    contact form:
    http://theodorakis.net/contact.html
     
    Nick Theodorakis, Feb 27, 2005
    #3
  4. Gunter Ganscher

    Richard Guest

    On Sat, 26 Feb 2005 13:40:15 -0700 Gunter Ganscher wrote:

    > 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


    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>
     
    Richard, Feb 27, 2005
    #4
  5. Nick Theodorakis wrote:
    > On Sat, 26 Feb 2005 13:40:15 -0700, Gunter Ganscher
    > <> wrote:
    >
    >
    >>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.


    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
     
    Gunter Ganscher, Feb 27, 2005
    #5
  6. Lauri Raittila wrote:
    > in alt.html, Gunter Ganscher wrote:
    >
    >>I am trying to search Google for information about coding standards with
    >>regards HTML and indentation,

    >
    > There is no standard.


    I find this odd. Almost every computer language I know has at least one
    or two published coding standards.

    >>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.


    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
     
    Gunter Ganscher, Feb 27, 2005
    #6
  7. Richard wrote:
    > 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
     
    Gunter Ganscher, Feb 27, 2005
    #7
  8. Gunter Ganscher <> wrote:

    > 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.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
     
    Jukka K. Korpela, Feb 27, 2005
    #8
  9. Gunter Ganscher wrote:

    > 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 <table> instead.

    > 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).

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Feb 27, 2005
    #9
  10. in alt.html, Gunter Ganscher wrote:
    > Lauri Raittila wrote:
    > > in alt.html, Gunter Ganscher wrote:
    > >
    > >>I am trying to search Google for information about coding standards with
    > >>regards HTML and indentation,


    > 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?


    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
     
    Lauri Raittila, Feb 27, 2005
    #10
  11. Gunter Ganscher

    Adrienne Guest

    Gazing into my crystal ball I observed Gunter Ganscher
    <> writing in news:eek:85Ud.22954$Tt.9757@fed1read05:

    > 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.

    --
    Adrienne Boswell
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
     
    Adrienne, Feb 28, 2005
    #11
  12. Gunter Ganscher

    Andy Dingley Guest

    It was somewhere outside Barstow when Gunter Ganscher
    <> wrote:

    >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.
     
    Andy Dingley, Mar 1, 2005
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth Porter
    Replies:
    9
    Views:
    410
    Kenneth Porter
    Oct 24, 2007
  2. Nikolai Weibull

    Indentation Style

    Nikolai Weibull, Aug 2, 2003, in forum: Ruby
    Replies:
    11
    Views:
    188
    Francis Hwang
    Aug 11, 2003
  3. Chris Dew
    Replies:
    103
    Views:
    792
    Frasier Mruby
    Oct 11, 2008
  4. Giles Bowkett
    Replies:
    36
    Views:
    346
    Trans
    May 30, 2007
  5. Jesse B.
    Replies:
    2
    Views:
    191
    Josh Cheek
    Mar 27, 2010
Loading...

Share This Page