In HTML, id is the abbreviation of "Identity document", which means "identity identification number". This attribute is used to specify the unique id of the element. This attribute can be used as a link anchor, through JavaScript or through CSS changes or adds styles to elements with specified ids.
The operating environment of this tutorial: Windows 10 system, HTML5 version, Dell G3 computer.
What does id mean in html
The id attribute specifies the unique id of the HTML element.
id must be unique within the HTML document.
The id attribute can be used as a link anchor to change or add styles to an element with a specified id via JavaScript (HTML DOM) or via CSS.
Differences between HTML 4.01 and HTML5
In HTML5, the id attribute can be used on any HTML element (it will validate any HTML element. But it is not necessarily useful).
In HTML 4.01, the id attribute cannot be used for: ,
, ,
,
, <script>, <style> ;, and <title>. <p>Note: HTML 4.01 has strict restrictions on id values (for example: in HTML 4.01 id values cannot start with a number). <p>Syntax<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false"><element id="id"></pre><div class="contentsignin">Copy after login</div></div><p>Attribute value</p><p>id specifies the unique id of the element. </p><p>Naming rules: </p><ul style="list-style-type: disc;"><li><p>Must start with the letters A-Z or a-z</p></li><li><p>Following characters: letters (A-Za -z), numbers (0-9), hyphens ("-"), underscores ("_"), colons (":") and periods (".")</p></li><li><p> Values are case sensitive </p></li></ul><p> Examples are as follows: </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false"><html>
<head>
<meta charset="utf-8">
<title>123</title>
<script>
function displayResult()
{
document.getElementById("myHeader").innerHTML="Have a nice day!";
}
</script>
</head>
<body>
<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">编辑文本</button>
</body>
</html></pre><div class="contentsignin">Copy after login</div></div><p>Output results: <p>Before clicking the button<p><img src="https://img.php.cn/upload/image/805/355/789/1641802775925527.png" title="1641802775925527.png" alt="What does id mean in html"/> <p>After clicking the button<p><img src="https://img.php.cn/upload/image/891/705/104/1641802783118131.png" title="1641802783118131.png" alt="What does id mean in html"/><p> Recommended tutorial: "<a href="http://www.php.cn/course/list/11.html" target="_blank" textvalue="html视频教程">html video tutorial"</script>
The above is the detailed content of What does id mean in html. For more information, please follow other related articles on the PHP Chinese website!