I am almost obsessed with perfect indentation and alignment when writing code, but for some reason I don't feel comfortable indenting HTML markup. Maybe because some times the level of indentation gets too deep, but I usually just (ab)use VIM's folding feature. Is this considered bad practice? What's your style with markup indentation?
I indent the same way I would with any XML style document (which XHTML is a subset of).
it doesnt matter much since you have tools like firebug, but i also try to get some new lines after the div, p, ul ect. elements. the main problem is that: when it looks good in my php code, it breaks in the produced html.
I do indent.
Also, whenever possible try to minimize over-nesting HTML. The simpler the markup the better. While building a deep hierarchy can make logical sense, it can be a practical nightmare for applying CSS & maintainance in general.
If you can, simplify your html. This will stop over-indentation and make it easier to read. Even better, depending on what server side technology you are using (if any) you might be able to break down complex files into seperate files (e.g. partial views in MVC or user controls in webforms etc.)
I'm fairly fanatical about indenting everything. HTML is included in this. I have some of my own little "rules" like, don't indent a <tr>
, and so on, but I do stick to my rules.
I do Indent, it keeps stuff readable. Consider indenting by 2 spaces instead of 4 or 8. I only indent block elements, put the rest on a single line.
must indent!! ... the following text from PEP8 - sums up how i try to do things in all languages..
*A Foolish Consistency is the Hobgoblin of Little Minds
A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important. But most importantly: know when to be inconsistent – sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!
Two good reasons to break a particular rule:
(1) When applying the rule would make the code less readable, even for someone who is used to reading code that follows the rules.
(2) To be consistent with surrounding code that also breaks it (maybe for historic reasons) – although this is also an opportunity to clean up someone else's mess.*
Yes !
if you use visual studio CTRL+K
CTRL+D
and everything gets organized this will make your life easier
I let my HTML be indented by my editor.
Honestly, what are these editors for otherwise?
it looks better if we indent and it is more readable too, but! indentation is the worst performance problem because the indentation is actually leaving lots of white spaces behind especially when the nesting gets deeper. try to write two html pages, make the 1st perfectly indented and the second without any indentation, you will notice that the second page is actually about 60% smaller in size(which means it loads faster in the browser).
i do perfect indentation during development but i switch to perfect minification on deployment.