Jump to content

Should ALL text be enclosed in paragraph tags?


Recommended Posts

I think I read somewhere that ALL text should be enclosed inside paragraph tags. But what I don't recall is it literally ALL text regardless of other tags? For example, inside <h-> tags, inside <div> tags, inside <li> tags, etc etc etc, should literally ALL text be enclosed in paragraph tags? In <li> tags if I use <p> tags then the text is dropped one line below the list item marker symbol, which is bad, so I don't use paragraph tags inside <li> tags. In <div> tags I have used paragraph tags only when there have been more than one paragraph. For years now I have been using paragraph tags for paragraphs outside of other tags, such as those I already mentioned, but should I be enclosing text in <h-> and <li> in paragraph tags? My goal is to write the most accurate markup possible.

Link to comment
Share on other sites

No, not all text, only paragraphs or sentences. Text should be contained by the HTML element that best describes it.

The <p> tag does not allow block elements, such as <h1-6> or <li>, as children. If you try to do it, the browser will implicitly close your paragraph where the next tag starts.

If you find yourself writing code like this:

<div class="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
<span>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>

Then you should change those to <p> tags.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...