开发者

Are <Ul>s allowed inside H1?

开发者 https://www.devze.com 2023-02-11 00:08 出处:网络
I was wondering if there would be any problems if I added a list inside a H1 heading: <h1> <ul开发者_如何转开发>

I was wondering if there would be any problems if I added a list inside a H1 heading:

<h1>
 <ul开发者_如何转开发>
  <li><a href="...">some link</a></li>
  <li><a href="...">another link</a></li>
  <li>current page</li>
 </ul>
</h1>

the list is a "breadcrumb" type navigation.

Or is it better to insert it inside the list?

<ul>
 <li><a href="...">some link</a></li>
 <li><a href="...">another link</a></li>
 <li><h1>current page</h1></li>
</ul>


Header elements like <h1> follow the phrasing content content model: if you wanted to follow the HTML specification to the letter, phrasing content can only contain regular text or other phrasing content. As <ul> elements aren't phrasing content, they're technically not allowed in <h1> elements.

Your second example—placing the <h1> elements within <li> elements—is valid markup and would be the preferred method of combining <h1> and <ul> elements.


It's not valid to have a ul inside a h1, the best way of checking is to use http://validator.w3.org/ to check your structure, that way the doctype you are using will be considered. (but it's still not valid!)


You can use W3C Markup Validation Service to check out whether or not it is valid :)


To answer your original question, no, that doesn't look like a sane thing to do with your markup, and even if it were technically valid (which I don't believe it is) I wouldn't advise doing it.

As for SEO, h1 is used to some degree in search, though I believe it's not as important as the <title> element. However, if your page doesn't have a heading, semantically-speaking, I certainly wouldn't crowbar one in just to try and improve rankings. Put that "current page" text in the <title>, if appropriate, make the breadcrumb list a normal breadcrumb list, and don't bother with the h1 if you don't need it.


this would display - however I think it would be considered bad practice as a list is not a header. You'd be better off adding css styling so you could format you list to the desired size, font etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消