Home > Enterprise >  Are we allowed to have <ruby> tags inside of html <p> tags?
Are we allowed to have <ruby> tags inside of html <p> tags?

Time:03-06

In the MDN Web Docs for ruby, it states that the permitted parents are:

Permitted parents Any element that accepts phrasing content.

However, when I follow that link to see what elements are considered phrasing content, the <p> tag is not listed.

So, does this mean that in order for me to use the <ruby> tags, I should wrap them in <span> tags for example? With and without, they both seem to be rendering properly.

Without span

<p>The word of the day is <ruby>
  明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp>
  </ruby></p>

With span

<p>The word of the day is <span><ruby>
  明日 <rp>(</rp><rt>Ashita</rt><rp>)</rp>
  </ruby></span></p>

CodePudding user response:

According the MDN docs, <ruby> is a type of phrasing content and is allowed inside any element that allows phrasing content. And the permitted content type for <p> is phrasing content. So <ruby> is allowed inside of <p>.

That link you were looking at is not a list of tags which allow phrasing content. It's a list of elements which are phrasing content, including <ruby> but excluding <p>. <p> falls in a broader category called flow content, so you can embed a <ruby> inside of a <p> but it would be illegal to embed a <p> inside of a <ruby> or even a <p> inside of a <p>.

  •  Tags:  
  • html
  • Related