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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...