Is header in legend valid?

Caption

2019-02-21 19:45发布

I use this in visual studio but the compiler claimed that h1 cannot be nested in legend element, but browser can render it anyway so i am confused that this is valid or not?

<fieldset>
   <legend>
     <h1>Caption</h1>
   </legend>
</fieldset>

7条回答
不美不萌又怎样
2楼-- · 2019-02-21 20:48

In HTML 5.2, this seems to be valid:

4.10.16. The legend element Content model: Phrasing content and headings (h1-h6 elements).

https://w3c.github.io/html/sec-forms.html#the-legend-element

This is very good news, as in complex forms, legends serve the same purpose as headings do, and e.g. screenreaders only announce legends when focusing a form element.

查看更多
登录 后发表回答