Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it semantically incorrect to place <h2> tags between <li> tags?

Tags:

html

I was planning to do something like this:

<ul class="menu">
 <li><h2>Contact</h2></li>
 <li>my email</li>
 <li>my phone</li>
</ul>

Is it semantically incorrect (or a bad practice?)

If the answer is yes, should I do this instead?

<ul class="menu">
 <li><strong>Contact</strong></li>
 <li>my email</li>
 <li>my phone</li>
</ul>

(I can't place just a heading tag, since there are not divs to group them):

<div id="branding">
<h1>
<ul class="menu">
<ul class="menu">
<ul class="menu serif">
<ul id="lang">
</div>
like image 386
alexchenco Avatar asked Jul 02 '11 03:07

alexchenco


People also ask

Can we use H2 tag inside UL tag?

For your code to be valid you can't put any tag inside a <ul> other than an <li> .

Can you put an h1 in an LI?

The HTML5 syntax rules allow heading elements h1 , h2 etc. inside li elements.

Can we use h1 tag in UL tag?

All HTML specifications forbid ul inside h1 , see e.g. HTML 4.01 on h1 (where the content model notation %inline; means text and text-level markup; this excludes list elements for example). So the h1 element embraces the list and continues after it.

What is the function of H2 tag?

An H2 tag marks the first sub-heading after your document's main heading. It defines the second-level headings on your webpage. Like an H1 tag, an H2 tag also appears larger than the rest of your main body text.


1 Answers

According to the W3C Validator using an <h2> tag inside a <li> tag is perfectly valid. This is much preferred ver using a <strong> tag with styling as this communicates the semantic intention of the text (and consequently helps with SEO).

like image 166
basicxman Avatar answered Nov 15 '22 07:11

basicxman