id=""

Browser
  • IE
  • Cr
  • Sf
  • Fx
  • O

The id attribute assigns a unique ID to an element.

The ID can be used to apply styles to the element. It can also be used to reference the element in JavaScript or create links to the element.

This attribute can be used in most elements.


<p id="example"></p>

Attribute Value Explanation
id=" " ID name arbitrary name

The ID name must be unique within a document.

Example


<html>
<head>
<title>TAG index</title>

<style type="text/css">
<!--
#example1 { color: red; font-size: 100%; }
#example2 { color: green; }
#example3 { color: blue; }
-->
</style>

</head>
<body>

<h1 id="example1">The ID name is example1</h1>
<p id="example2">The ID name is example2</p>
<p id="example3">The ID name is example3</p>

</body>
</html>

Output

The ID name is example1

The ID name is example2

The ID name is example3