HTML tags on separate lines?


Beginner question regarding HTML element tags. When creating tags, is it considered better form to put the opening and closing tags on separate lines? Example: when i am creating a head element, but have not decided the element contents: is it “proper” to create it like this:


or like this:


I guess example 2 is better for organization. Is that the only difference?


Well it depends in the tags, I try to have head, body and All the other big tags to put Them on seperate lines, the same with DIV’s where it makes sense, and the p tags and h1 and the kind i often put on the same line.


This is a matter of preference… I think. I second @Kristianfriis for readability. In your example, I would prefer ex2. Simply because I know I’ll put more than 1 line there when I get back to it. If you have Emmet installed in your code editor, just hit ‘!’ then tab. This is what I do. I just let it fill the structure for me.


The 2nd version is better for readability and the most preferred.


I’ve seen this done both ways and it is personal preference, there is no right or wrong answer.

If something is rather short, like a page title, I tend to keep them on the same line, it just makes more sense to me personally.

However, if things get really long / lengthy then I’ll add them to separate lines. I think in terms of which is most used, you’ll get much debate about, over the years I’ve been working with HTML files, I’ve seen an equal amount of both and seen HTML files that do both within the same file.


my preference
block level elements better be in separate lines
inline in one line