我知道标题标签是出于语义目的,只要你不滥用它们的目的,理论上,你不应该在搜索引擎中受到惩罚......但是多长时间才算太长呢?
我一直觉得这是一条不言而喻的规则,即不应将整个段落放在 h*
标记中,即使是 h4
- h6
,但我从来没有真正质疑过这是对还是错。但是 15-20 个单词的句子呢?线在哪里?如果没有明确的字符/字数限制,那么在选择 h*
标签而不是 p.subtitle
之类的标签时,我应该遵守哪些限制?
我知道我可能想得太多了,但仍然希望得到一些反馈。
最佳答案
HTML 规范的内容
HTML 规范没有定义这样的限制,无论是对于 h1
-h6
还是任何其他元素。
人们期望提及这种限制的地方是元素的定义本身( The h1
, h2
, h3
, h4
, h5
, and h6
elements )或元素的内容模型( phrasing content )。具体来说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>
关于html - 标题标签有最大字符数/字数限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43337901/