简体   繁体   English

HTML 标题是否有长度限制? (h1, h2 等)

[英]Is there a length limit for a HTML heading? (h1, h2 etc)

Is it valid HTML5 to have a long sentence as a h2 ? HTML5 有一个长句作为h2有效吗?

For example:例如:

<hgroup>
  <h1>
    Food & Drink Products
  </h1>
  <h2>
    There are 5000 food products near you in 100 categories from brands like FoodX, DrinkY, and FoodStuffsZ.
  </h2>
</hgroup>

Or would a p tag more appropriate?还是p标签更合适?

I'm asking because the importance of this text is that of a h2 , but it reads like a paragraph and I could not find an example like this or any mention of heading length on the HTML spec .我问是因为这段文字的重要性是h2的重要性,但它读起来像一个段落,我找不到这样的例子,也找不到HTML 规范中标题长度的任何提及。

You should mark up your text based on what is appropriate for the content you are showing , according to most copy-writing and SEO guidelines.根据大多数文案写作和 SEO 指南,您应该根据适合您所显示内容的内容来标记您的文本。

There is no limit on heading length from a HTML perspective , but you need to consider it from other, arguably more important, perspectives:从 HTML 的角度来看标题长度没有限制,但是你需要从其他的,可以说更重要的角度考虑:

  • Readability & UX : Headings that are too long can be difficult to read, and could therefore affect usability and users experience.可读性和用户体验:太长的标题可能难以阅读,因此可能会影响可用性和用户体验。 It can also affect the overall appearance of the page and make it look unbalanced or as if you are trying to over-optimise the page which can give a poor impression to users.它还会影响页面的整体外观并使其看起来不平衡,或者好像您正在尝试过度优化页面,这会给用户留下不好的印象。
  • Effectiveness : The shorter and snappier a heading is (without losing meaning of course), the easier it is for users to take it in quickly and the better it gets the message across.有效性:标题越短越活泼(当然不会失去意义),用户越容易快速接受它,并且它能更好地传达信息。 That's why slogans and taglines work in marketing!这就是口号和标语在营销中起作用的原因!
  • SEO : We know that Google pays most attention to the first 60-70 characters in a page title which is generally the same as the h1 . SEO :我们知道Google最关注页面title中的前60-70个字符,一般与h1相同。 I don't know of any data about how they consider h2 or any other subheadings, but their aim is to appraise pages in the same way humans do.我不知道关于他们如何考虑h2或任何其他副标题的任何数据,但他们的目标是以与人类相同的方式评估页面。 So if they think that overly-long headings are not "user-friendly" then they might not rate it, or worse, penalise the page for attempting to "game" the SEO system.因此,如果他们认为过长的标题不是“用户友好的”,那么他们可能不会对其进行评级,或者更糟的是,惩罚试图“玩弄” SEO 系统的页面。

In summary : As I mentioned earlier, the advice for usability, SEO and general copywriting is to do what makes sense for your own content.总结:正如我之前提到的,对可用性、搜索引擎优化和一般文案写作的建议是做对你自己的内容有意义的事情。 So if it makes sense then do it, but in most cases there is no need for long heading and it could a sign that the text needs improvement, and a shorter version would probably work better:)因此,如果它有意义,那就去做吧,但在大多数情况下,不需要长标题,它可能表明文本需要改进,而较短的版本可能会更好:)

In the example in your question , I wouldn't consider that text a heading - it sounds more like a paragraph.在您问题的示例中,我不会将该文本视为标题 - 它听起来更像是一个段落。 A heading would be something like " 5000 Food Products Near You in 100 Categories ", with the next text being info about the products and categories.标题类似于“您附近的 5000 种食品,分为 100 个类别”,下一个文本是有关产品和类别的信息。

If you want to be precise, use h1 or h2 for headlines and p for paragraphs.如果要精确,请使用h1h2作为标题,使用p作为段落。 Long headlines are fine, there's no rule saying headlines shouldn't be long.标题长就好,没有规定标题不能长。

Also, truth of the matter is, it doesn't matter so much.而且,事情的真相是,这并不重要。 If you choose p over h2 , as long as it works well for you, that's fine.如果您选择p而不是h2 ,只要它适合您,那很好。

There are far more important things, such as writing a responsive website, clean code, etc.还有更重要的事情,例如编写响应式网站、干净的代码等。

That definitely depends on what you want.这绝对取决于你想要什么。 If h2 suffices for you use that.如果h2足以满足您的需求,请使用它。 I myself would prefer to use <p> for that and then chance css for my liking.我自己更愿意为此使用<p> ,然后根据自己的喜好使用 css。

There are no problems to use headers as a paragraph, but the question is for what?标题作为段落没有问题,但问题是为了什么? If you just want to highlight the text, use a p with a class, it is much better如果你只是想突出显示文本,使用带有 class 的p ,它会好得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM