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>
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.
HTML <legend> Tag The legend tag is used to define the title for the child contents. The legend elements are the parent element. This tag is used to define the caption for the <fieldset> element.
The head element contains meta data about the document. The header element contains any items that should contain introductory information and often includes things like h1 elements, logos, and things about the author or company. Very often, it will also contain a navigation bar.
The H1 tag is an HTML heading that's most commonly used to mark up a web page title. Most websites use CSS to make the H1 stand out on the page compared to lesser headings like H2, H3, etc.
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.
In HTML5 elements allowed inside <legend>
elements are those in the Phrasing Content group. Per the docs:
Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With