标题标签是否有最大 character/word 限制?

Is there a max character/word limit for heading tags?

我知道标题标签是为了语义目的,只要你不滥用它们的目的,理论上,你不应该在搜索引擎中受到惩罚......但是多长时间太长了?

我一直觉得这是一个潜规则,你不应该把整个段落放在 h* 标签中,即使是 h4-h6,但我从来没有真正质疑过这是对还是错。但是 15-20 个单词的句子呢?线在哪里?如果没有明确的 character/word 限制,在选择 h* 标签而不是 p.subtitle?

时,我应该注意哪些限制?

我知道我可能 over-thinking 这个,但还是希望得到一些反馈。

HTML 规范的内容

HTML 规范没有定义这样的限制,h1-h6 和任何其他元素都没有。

人们期望提到这种限制的地方是元素的定义本身(The h1, h2, h3, h4, h5, and h6 elements) or the element’s content model (phrasing content). Specifically the definition of Text 没有提到任何限制。

在其关于解析的部分中,HTML 5.1 规范 notes(粗体强调我的):

The algorithm described below places no limit on the depth of the DOM tree generated, or on the length of tag names, attribute names, attribute values, Text nodes, etc. While implementors are encouraged to avoid arbitrary limits, it is recognized that practical concerns will likely force user agents to impose nesting depth constraints.

所以用户代理通常会有自己的限制,但这些限制会非常高。

在实践中

我认为讨论非正式限制没有意义。标题应该尽可能长。想想科学论文或小说等作品的长标题,例如 this book has more than 50 words in its title:

<h1 class="book-title">
    Noisy outlaws, unfriendly blobs, and some other things that 
    aren't as scary, maybe, depending on how you feel about lost 
    lands, stray cellphones, creatures from the sky, parents who 
    disappear in Peru, a man named Lars Farf, and one other story 
    we couldn't quite finish, so maybe you could help us out
</h1>

也就是说,不要滥用标题元素当然很重要。如果您有 subheading, subtitle, alternative title or tagline,请不要使用标题元素。标记这些案例的常用方法是使用 header 元素、一个标题元素和一个或多个 p 元素,例如:

<header>
  <h1><!-- the actual heading --></h1>
  <p><!-- the subheading or similar --></p>
</header>