HTML tags on separate lines?


#1

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:

Screenshot_2019-08-30%20Introduction%20to%20HTML%20Codecademy

or like this:

Screenshot_2019-08-30%20Introduction%20to%20HTML%20Codecademy(1)

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


#2

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.


#3

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.


#4

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


#5

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.