nomnex Posted May 19, 2010 Share Posted May 19, 2010 It visually clearer for me at the moment to write one tag per line, although it lengthens every page. <p>Some text<a href=""></a>Some text</p>vs.<p>some text <a href=""></a> Some text</p> Is there any "best practice" (if any) for HTML tag layout on HTML page? This question also applies to HTML tag indents. I use indents for tables and lists, so far: One indent for each sub-level. <table>-<tr>--<td>--</td>--</tr></table> If you have some link reference or general advice, I glad to read you. Link to comment Share on other sites More sharing options...
Synook Posted May 19, 2010 Share Posted May 19, 2010 Generally, you should indent all children one level more than their parent. Anything else is really preference. Link to comment Share on other sites More sharing options...
dink Posted May 19, 2010 Share Posted May 19, 2010 It visually clearer for me at the moment to write one tag per line, although it lengthens every page.<p>Some text<a href=""></a>Some text</p>vs.<p>some text <a href=""></a> Some text</p> Is there any "best practice" (if any) for HTML tag layout on HTML page? This question also applies to HTML tag indents. I use indents for tables and lists, so far: One indent for each sub-level. <table>-<tr>--<td>--</td>--</tr></table> If you have some link reference or general advice, I glad to read you. As stated child elements should be indentedI still put everything on a separate line and indent when needed. It makes it easier to read the code just in case something is wrong or some one else needs to look at your code.If your page is not working properly it is easy to comment out one line of code than try to find the right place for a comment tagWhen using programming languages it makes it much easier to debug.Hope this helps,dink Link to comment Share on other sites More sharing options...
nomnex Posted May 19, 2010 Author Share Posted May 19, 2010 yes, it helps. Thanks to both of you.Synook, since you have experienced writing HTML, do you still use a tag/line or only for some type of tags? When I look at the code of the page, the tags are usually on a single line to save space, I guess. On the other hand it hard to read (as dink says) Link to comment Share on other sites More sharing options...
Synook Posted May 19, 2010 Share Posted May 19, 2010 Hrmm, well, most of my HTML is now generated using PHP or similar, and so comes out (splat) all in one big line. However, I generally write block-level elements on their own line but type inline elements, well, in-line. Link to comment Share on other sites More sharing options...
nomnex Posted May 19, 2010 Author Share Posted May 19, 2010 I generally write block-level elements on their own line but type inline elements, well, in-line.Got it. Link to comment Share on other sites More sharing options...
ShadowMage Posted May 19, 2010 Share Posted May 19, 2010 Hrmm, well, most of my HTML is now generated using PHP or similar, and so comes out (splat) all in one big line.That's what the newline escape character is for. Link to comment Share on other sites More sharing options...
Synook Posted May 19, 2010 Share Posted May 19, 2010 That's what the newline escape character is for.Yah, but why bother? It's clear and easily readable in the server-side code, that's all I need. Link to comment Share on other sites More sharing options...
ShadowMage Posted May 19, 2010 Share Posted May 19, 2010 Yah, but why bother? It's clear and easily readable in the server-side code, that's all I need. I find myself looking at my generated source code quite often for debugging. Sure I can echo things out, but sometimes it's nice to be able to look at the big picture, too. Link to comment Share on other sites More sharing options...
Err Posted May 27, 2010 Share Posted May 27, 2010 I usually indent child elements with two spaces. It makes the indention stand out more.When I work with PHP generated code I try my best to go with the flow of the indention of the source code. I usually do the below format to keep my indentions consistent. Doing this also helps me spot the generated HTML code faster and is visually easier to read. $txt .= "<table>\n". " <tr>\n". " <td></td>\n". " </tr>\n". "</table>\n"; Link to comment Share on other sites More sharing options...
Synook Posted May 28, 2010 Share Posted May 28, 2010 If you really want to keep your HTML tidy inside your server-side files, then why not use a templating engine? As I mentioned in another thread, if you just want it to be tidy on the client-side you can always use Tidy. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.