0

Is my friend right regarding my question? Do I need to always close <p> tag with a </p> tag like this:

<p>Paragraph text goes here</p>
<p>Another paragraph.</p>

Or is it OK to write it like this:

<p>Paragraph text goes here.
<p>Another paragraph.
bodacydo
  • 75,521
  • 93
  • 229
  • 319
  • It doesn't need to be closed. Some people use it as a return line, some use it as a CSS attribute... Personally, I prefer to use

    as a return line, alongside with
    . As for CSS, I prefer using id, class...

    – Lord Rixuel Sep 27 '15 at 00:38
  • Define "need". If you want to have valid XHTML, then yes, there needs to be a closing tag. If you just want your page to look nice in the major browsers, then no, they all tend to be very forgiving* of unclosed/unbalanced tags. If you want to ensure your page behaves as consistently as possible in as many different contexts as possible, then you're usually better off explicitly closing your tags. (* fixed typo in previous comment) – aroth Sep 27 '15 at 00:49

1 Answers1

1

In my experience its best to always include a closing tag. This is good for a few reasons:

If you are including your code into third party systems there is no telling what they are going to do to your code to make it valid.

E.G. in gmail you may find the second P tag to be completely removed whereas Outlook may close the first before the second P tag starts. Its best to keep things consistent.

Another example would be where Scrapers are generally going to need the HTML on the page to be as close to valid XML as possible in order to get the data they need.

It really depends on how you are using the code. My suggestion is to always close the tag but if for some weird reason you need to do it like that above just make sure to test test test... and test some more.

Jimmy Scray
  • 144
  • 2
  • 14