Home > Web Front-end > Front-end Q&A > What does id mean in html

What does id mean in html

WBOY
Release: 2022-01-10 16:20:12
Original
12540 people have browsed it

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.

What does id mean in html

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&gt ;, 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">&lt;element id=&quot;id&quot;&gt;</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">&lt;html&gt; &lt;head&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;title&gt;123&lt;/title&gt; &lt;script&gt; function displayResult() { document.getElementById(&quot;myHeader&quot;).innerHTML=&quot;Have a nice day!&quot;; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 id=&quot;myHeader&quot;&gt;Hello World!&lt;/h1&gt; &lt;button onclick=&quot;displayResult()&quot;&gt;编辑文本&lt;/button&gt; &lt;/body&gt; &lt;/html&gt;</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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template