Ul can´t be child of p, but why?

I just learned, that an <ul> element or <ol> element can never be a child of a <p> element. I was wondering, why is that?

The answer provided here is a really good answer to your question.

Basically, it’s because "ol elements are not legally allowed inside p elements." It’s something that is set by the HTML spec.

1 Like

So basically the answer is, it is not allowed, because it is forbidden :joy::+1: But I found the answer in the link you posted - obviously both <p> and <ol> are block elements and you cannot nest one block element in another. Makes sense, now that I think about it :thinking:

i do not know man …

1 Like

Amazing first post hineta :joy: The only wisdom is to know, that we know nothing!

Haha, yea it seems a bit of a nitpick.

One thing to note is that block elements can be nested inside of other block elements. In fact that’s quite common! So you can put a <ul> inside of a <div> without any trouble.

It’s just that paragraph tags are a specific type of block element, and they only really want text inside of them, because they’re meant for paragraphs. That’s why your browser complains when you try to put <ul>, <ul>, <div> inside of them.