Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is header in legend valid? <legend><h1>Caption</h1></legend>

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>
like image 600
Sarawut Positwinyu Avatar asked Nov 04 '11 07:11

Sarawut Positwinyu


People also ask

Can a legend be a heading?

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.

What is a legend in HTML?

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.

What is new about the relationship between the header and h1 tags in html5?

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.

What is h1 tag in HTML?

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.


2 Answers

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.

like image 161
Joshua Muheim Avatar answered Sep 27 '22 21:09

Joshua Muheim


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.

like image 31
Jordan Running Avatar answered Sep 27 '22 20:09

Jordan Running