Should HTML tags appear on their own separate line?

Viewed 30

Which is better, putting an HTML element's tags on the same line as its content or on separate lines? For example:

<p>Hello World!</p>

versus

<p>
  Hello World!
</p>

Is there a styling convention that covers this? Or is this simply a matter of preference/consistency like the debate on whether curly braces should appear on their own line?

1 Answers

For me. Both of the above methods work. But:

The first way is using short content:

<p>Hello World!</p> 

Second, I always use it when I have large content, or using framework CSS like bootstrap, tailwind CSS.... or If you use VsCode when you format document it will be like this for larger content.

  <p class="mt-2 text-base leading-6">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
      Voluptatibus quia, nulla! Maiores et perferendis eaque, 
      exercitationem praesentium nihil.
  </p>

I recommend the second way. Easy to read code

Related