The id attribute provides a unique identifier for an element within the document. It may be used by an a element to create a hyperlink to this particular element.
id属性为文档中的元素提供唯一的标识符。 元素可以使用它来创建到此特定元素的超链接。
This identifier may also be used in CSS code as a hook that can be used for styling purposes, or by JavaScript code (via the Document Object Model, or DOM) to make changes or add behavior to the element by referencing its unique id.
此标识符也可以在CSS代码中用作可用于样式设计的挂钩,或由JavaScript代码(通过文档对象模型或DOM)用作JavaScript,以通过引用元素的唯一ID进行更改或为元素添加行为。
Note that the id attribute cannot be applied to the following elements:
请注意,id属性不能应用于以下元素:
base
base
head
head
html
html
meta
meta
script
script
style
style
title
title
<span id="thisspan">A uniquely identifiable element.</span>The most important aspect of the id attribute is that it must be absolutely unique. Unlike the class attribute, which may apply the same value to many elements in a page, an id that’s applied to an element must not match an id used anywhere else on the same page.
id属性最重要的方面是它必须绝对唯一。 不同的是类属性,它可以应用相同的值,许多元素在一个页面,一个id是套用至元素必须不匹配的id其他任何地方使用在同一页上。
The id attribute value must begin with a letter in the roman alphabet (a–z or A–Z); this can be followed by any combination of letters (a–z or A–Z), digits (0–9), hyphens (-), underscores (_), colons (:), and periods (.). The id value is case sensitive, thus <span id="me">This is me</span> and <span id="ME">This is me</a> would be considered to be separate and uniquely identifiable elements on the same web page.
id属性值必须以罗马字母(az或AZ)开头。 后面可以跟字母(a–z或A–Z),数字(0–9),连字符(-),下划线(_),冒号(:)和点号(。)的任意组合。 id值区分大小写,因此<span id="me" >This is me</span>和<span id="ME" >This is me</a>将被认为是单独的且在元素上唯一可识别的元素相同的网页。
翻译自: https://www.sitepoint.com/id-html-attribute/