×
   ❮     
HTML CSS MySql Javascript SQL PYTHON JAVA C++ C# BOOTSTRAP REACT XML NODEJS ANGULAR DJango Rust Android VUE
     ❯   

HTML Id


What is Id in HTML?

HTML Id used to specify a unique id for an HTML element.

You cannot have more than one element with the same id in an HTML document.


Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>HTML id Example</title>
  <style>
    #content-container p {
      color: red;
    }
  </style>
</head>
<body>
  <h1 id="main-heading">Heading 1</h1>
  <div id="content-container">
    <p>This is a paragraph inside a div with the id "content-container".</p>
  </div>
</body>
</html>
Try it Yourself »

The id attribute can also be used by JavaScript

JavaScript can access an element with a specific id with the getElementById() method:

Example

<script>
  function displayResult() {
    document.getElementById("header").innerHTML = "<span style="color: brown;">Hello!</span>";
  }
</script>
Try it Yourself »

Hey there! Let's go for Learn fasta then! It is more than just coding; it is to have the superpower that can solve any problem. Through simple and easy-to-grasp examples you will sail through the learning process. In addition, it is not just about coding– you will acquire competencies on how to solve complex problems, analyze data, and come up with efficient solutions. Shall we start this wonderful journey together! learnfasta.com terms of use, Copyright 2025 All Rights Reserved.