id - HTML: HyperText Markup Language 编辑

The id global attribute defines an identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).

This attribute's value is an opaque string: this means that web authors should not rely on it to convey human-readable information (although having your IDs somewhat human-readable can be useful for code comprehension, e.g. consider ticket-18659 versus r45tgfe-freds&$@).

id's value must not contain whitespace (spaces, tabs etc.). Browsers treat non-conforming IDs that contain whitespace as if the whitespace is part of the ID. In contrast to the class attribute, which allows space-separated values, elements can only have one single ID value.

Note: Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in HTML 4. Though this restriction has been lifted in HTML5, an ID should start with a letter for compatibility.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'id' in that specification.
Living StandardNo change from latest snapshot, HTML 5.1
HTML 5.1
The definition of 'id' in that specification.
RecommendationSnapshot of HTML Living Standard, no change from HTML5
HTML5
The definition of 'id' in that specification.
RecommendationSnapshot of HTML Living Standard, now accept '_', '-' and '.' if not at the beginning of the id. It is also a true global attribute.
HTML 4.01 Specification
The definition of 'id' in that specification.
RecommendationSupported on all elements but <base>, <head>, <html>, <meta>, <script>, <style>, and <title>.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:60 次

字数:5797

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文