Horje
What is HTML id Attribute

Definition and Usage

The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.


Browser Support

Syntax

<element id="id">

Attribute Values

Value Description
id Specifies a unique id for the element. Naming rules:
  • Must contain at least one character
  • Must not contain any space characters

How to Use the id attribute to manipulate text with JavaScript

See id Example.
index.html
Example: HTML
<!DOCTYPE HTML>
<html>
<body>

<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">Change text</button>

<script>
function displayResult() {
  document.getElementById("myHeader").innerHTML = "Have a nice day!";
}
</script>

</body>
</html>

Output should be:

How to Use the id attribute to manipulate text with JavaScript

How to Use the id attribute to link to an element with a specified id within a page

There is a link at the bottom of the page!
index.html
Example: HTML
 <html>
<body>

<h2><a id="top">Some heading</a></h2>

<p>Lots of text....</p>
<p>Lots of text....</p>
<p>Lots of text....</p>

<a href="#top">Go to top</a>

</body>
</html> 

Output should be:

How to Use the id attribute to link to an element with a specified id within a page

How to Use the id attribute to style text with CSS

Id uses to the css and html Style.
index.html
Example: HTML
<!DOCTYPE HTML>
<html>
<head>
<style>
#myHeader {
  color: red;
  text-align: center;
}
</style>
</head>
<body>

<h1 id="myHeader">Horje is the best!</h1>

</body>
</html>

Output should be:

How to Use the id attribute to style text with CSS




html id attribute

Related Articles
What is HTML accesskey Attribute HTML Global Attributes
What is HTML class Attribute HTML Global Attributes
What is HTML contenteditable Attribute HTML Global Attributes
What is HTML data-* Attributes HTML Global Attributes
What is HTML dir Attribute HTML Global Attributes
What is HTML draggable Attribute HTML Global Attributes
What is HTML enterkeyhint Attribute HTML Global Attributes
What is HTML hidden Attribute HTML Global Attributes
What is HTML id Attribute HTML Global Attributes
What is HTML inert Attribute HTML Global Attributes
What is HTML inputmode Attribute HTML Global Attributes
What is HTML lang Attribute HTML Global Attributes
What is HTML popover Attribute HTML Global Attributes
What is HTML spellcheck Attribute HTML Global Attributes
What is HTML style Attribute HTML Global Attributes
What is HTML tabindex Attribute HTML Global Attributes
What is HTML title Attribute HTML Global Attributes
What is HTML translate Attribute HTML Global Attributes
What are the HTML Global Attributes HTML Global Attributes

Single Articles
How to Use the id attribute to manipulate text with JavaScriptHTML Global Attributes
How to Use the id attribute to link to an element with a specified id within a pageHTML Global Attributes
How to Use the id attribute to style text with CSSHTML Global Attributes

Read Full:
HTML Global Attributes
Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Global Attributes
Uploaded by:
Admin
Views:
30


Reffered: https://www.w3schools.com/tags/att_global_id.asp