Html 标题属性的最大长度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8516235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:01:51  来源:igfitidea点击:

Max length of Title Attribute

htmltitle

提问by ArK

What is the length limitation of HTML titleattribute?

HTMLtitle属性的长度限制是多少?

<span title="some big long piece of text and is there any limit to its size?" />

Edit:

编辑:

My question is specific to title attribute not general

我的问题是针对 title 属性而不是一般性的

采纳答案by Ashkan

Titles are limited to 512 total characters in internet explorer according to MSDN.

根据 MSDN,Internet Explorer 中的标题总数限制为 512 个字符。

http://msdn.microsoft.com/en-us/library/ie/ms534683(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/ie/ms534683(v=vs.85).aspx

回答by Jonathan Basile

I just tried this out for Chrome, Safari, and Firefox with HTML5:

我刚刚用 HTML5 在 Chrome、Safari 和 Firefox 上尝试了这个:

Chrome limits to 1024.

Chrome 限制为 1024。

Safari had no limit (I tried up to 3250)

Safari 没有限制(我尝试了 3250)

Firefox also had no limit up to 3250. As @jukka mentioned, though, Firefox does not automatically insert linebreaks.

Firefox 也没有限制到 3250。不过,正如@jukka 提到的,Firefox 不会自动插入换行符。

回答by Jukka K. Korpela

There is no limit in the specifications, but when you go past 48 characters, browsers will treat it differently—IE breaks the text to two or more lines, whereas Firefox doesn't. Firefox doesn't honor explicit line breaks in source (this is, debatably, correct behavior).

规范中没有限制,但是当您超过 48 个字符时,浏览器会对其进行不同的处理——IE 将文本分成两行或更多行,而 Firefox 不会。Firefox 不支持源代码中的显式换行(这是有争议的正确行为)。

So the practical conclusion is: if you need to ask, it's too long, and you should use some other technique. The title attribute is normally used for the “tooltip” effect, and similar effects can be created (with better usability) using CSS (and possibly JavaScript).

所以实际的结论是:如果你需要问,它太长了,你应该使用一些其他的技巧。title 属性通常用于“工具提示”效果,并且可以使用 CSS(可能还有 JavaScript)创建类似的效果(具有更好的可用性)。

回答by kevinji

There is no length limitation in either HTML 4.01or HTML5, although long tooltips are usually a sign that you should be placing that text elsewhere, possibly before or after. (I said "usually" because xkcduses the tooltips effectively, though the description couldstill be put underneath the image with the same relative effect.)

HTML 4.01HTML5 中没有长度限制,尽管长工具提示通常表明您应该将该文本放置在其他地方,可能在之前或之后。(我说:“通常”,因为XKCD使用有效的工具提示,虽然描述可能仍然以相同的相对影响图像下面放。)

回答by span

The implementation in browsers differ but I think HTML 4.01 is 128 chars. I've seen limits from 80 chars up to 2000 being mentioned on the web.

浏览器中的实现有所不同,但我认为 HTML 4.01 是 128 个字符。我在网上看到过从 80 个字符到 2000 个字符的限制。

回答by Roman Newaza

According W3C,

根据 W3C,

The title should ideally be less than 64 characters in length. That is, many applications will display document titles in window titles, menus, etc where there is only limited room. Whilst there is no limit on the length of a title (as it may be automatically generated from other data), information providers are warned that it may be truncated if long.

理想情况下,标题的长度应少于 64 个字符。也就是说,许多应用程序将在窗口标题、菜单等空间有限的地方显示文档标题。虽然标题的长度没有限制(因为它可能是从其他数据自动生成的),但警告信息提供者,如果它很长,它可能会被截断。

Check it out: The TITLE element in HTML

检查一下:HTML 中的 TITLE 元素