Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    15
    Thanks
    1
    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 03:05 AM.

  • #2
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    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:

    Code:
    <ul>
        <li></li>
    </ul>
    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.

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

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,636
    Thanks
    6
    Thanked 1,003 Times in 976 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
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    1
    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
    •