Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2012
    Thanked 0 Times in 0 Posts

    Indenting with HTML

    I've been looking at different page sources on the net and I've noticed there are variations in the way the code is usually indented. I would like to know if there are standards to follow as to what's the right indenting technique/style to use or if this is more of a preference?

    For example, in some pages, especially parts containing images and links inside ul and li tags, sometimes I see the code horribly piled up which makes it really hard to read. How can someone, even experienced web developers actually read that?

    I've gotten used to always hand writing my html and it seems to me it looks sometimes kind of empty as I always try to separate things so that they are easy to read. But then when I randomly choose websites and view the code, often times the codes I see are much more condensed, some of them left-justified, some of them piled up, etc.

    I don't have work experience in web development but I do like to develop websites, I'm simply trying to adopt good coding practices. I guess companies take that into consideration when hiring a developer ???

    Any comments, suggestions or recommendations on good articles to read will be much appreciated.
    Last edited by knightmetal; 09-18-2012 at 04:05 AM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Thanked 241 Times in 240 Posts
    For the most part, it just depends on the programmer's style.

    Most programmers indent things with the "tab" key:

    However the code you see on a live website is often different than what the programmers developed it with.

    Many websites condense their code, some even go as far as condensing it into 1 line (you see that with CSS a lot).
    Take a look at these website's CSS: http://www.youtube.com/ https://twitter.com/ (1 line condensed CSS)

    If you see code all condensed, chances are they didn't develop it like that. Any experienced programmer would be smart enough to make the code as simple as possible to read while developing (nicely indented), however when it comes to making the code live (putting it on a live website), many large websites with high traffic, condense the code as it speeds up page load time and server load:

    HTML compressor CSS compressor

    As a beginning developer, you should definitely make your code easy to read, indent things so that you can easily read it and since your websites probably won't get high traffic, I would highly recommend you just publish your code as you wrote it (no need to compress and save half a second).
    It's easy to get consumed with how your code looks on view source, but let me reassure you that that will improve naturally with your time in programming.

    Last edited by Sammy12; 09-18-2012 at 04:37 AM.

  3. #3
    Administrator VIPStephan's Avatar
    Join Date
    Jan 2006
    Halle (Saale), Germany
    Thanked 1,299 Times in 1,269 Posts
    Also, the indenting cannot always be controlled completely by the developer since many websites run on a server side script (PHP/ASP/JSP…), for example if powered by a CMS, which compiles the pages from snippets and contains a lot of conditionals etc. that might be indented themselves for ease of reading even though you don’t see them in the output source code eventually. So you might see a “dirty” output source code even though the code snippets are “clean” for themselves.

  4. #4
    New Coder
    Join Date
    Sep 2012
    Thanked 0 Times in 0 Posts
    Guys, thanks a lot for your comments!

    I guess my problem is that I don't know what to look at or what to improve in my codes. I've been working on my portfolio lately so that if I get a job offer or something then I'm able to show "something", then they'll know what to expect from me. It's just hard not have friends or someone who can give you tips, suggestions or constructive criticism, even though I know there's plenty of information on the internet about this topic. That's why I decided to turn to forums and clarify the doubts I had.

    Your comments were useful, thanks!!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts