Are
    s allowed inside H1?

前端 未结 5 1729
执笔经年
执笔经年 2021-01-18 09:23

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

相关标签:
5条回答
  • 2021-01-18 09:51

    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.

    0 讨论(0)
  • 2021-01-18 09:58

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

    0 讨论(0)
  • 2021-01-18 09:58

    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.

    0 讨论(0)
  • 2021-01-18 09:58

    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 讨论(0)
  • 2021-01-18 10:08

    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!)

    0 讨论(0)
提交回复
热议问题