Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unordered list in a paragraph element

Tags:

html

People also ask

How do you make a list in a paragraph in HTML?

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

How do you write a list in a paragraph?

If you are including a simple, relatively short list of three to five items within a paragraph —also known as a series—the proper formatting is to: (a) precede the list with a comma, (b) label each item with a lowercase letter enclosed in parentheses, and (c) separate each item with commas or semicolons.

What element is unordered list?

<ul>: The Unordered List element. The <ul> HTML element represents an unordered list of items, typically rendered as a bulleted list.

What are the 3 types of unordered list?

There are three types of lists in HTML: Unordered list or Bulleted list (ul) Ordered list or Numbered list (ol) Description list or Definition list (dl)


According to the HTML 5 specification, a paragraph may contain phrasing content, which still does not include other grouping elements:

http://www.w3.org/TR/html5/grouping-content.html#the-p-element

According to the HTML 4.01 specification, a paragraph may only contain inline elements:

http://www.w3.org/TR/html401/struct/text.html#h-9.3.1

9.3.1 Paragraphs: the P element

<!ELEMENT P - O (%inline;)*            -- paragraph -->
<!ATTLIST P
  %attrs;                              -- %coreattrs, %i18n, %events --
  >

The correct markup in this case is to close your paragraph before starting the list.

Alternatively, you can use another tag other than paragraph (like <div>) which is not processed in this way.

<div>
   <ul> ... </ul>
</div>

I just had this issue and did not want to enclose it in a DIV since I was using P for the rest of that page and all pages. Instead I styled SPANs to behave like LIs.

SPAN.li  {display: list-item; margin-left: 2em}
<P>These issues are currently on my mind
<SPAN class=li>My hat</SPAN>
<SPAN class=li>Global warming</SPAN>
<SPAN class=li>Global cooling</SPAN>
<SPAN class=li>Global terrorism</SPAN>
<SPAN class=li>Global narrow-mindedness</SPAN></P>

Lists aren't allowed in paragraphs - there's no way to do it, it's semantically impossible.

If you want the list to inherit styles from the paragraph, just add the UL element to the same CSS styles as your P elements:

eg:

p, ul { font-size: 12px; }

or better yet, encase both elements in something logical (section, article, div).

You've got to ask yourself why you want the list inside the paragraph. If it's because you want them styled the same, then you want them both in the same containing element, eg:

<article>
    <p>Paragraph of text</p>
    <ul>
        <li>List</li>
    </ul>
    <p>Next paragraph</p>
</article>

and then style the article.