#16 HTML id Attribute

In HTML id attribute used to specify a unique id for the HTML element. You cannot have more than one element with the same id in an HTML document.

The id Attribute

HTML id attribute used to specify a unique id for the HTML element. The value of the id attribute must be unique through out the HTML file.

In CSS id element used to point the specific style. Also same in JavaScript. Use to point specific element in JavaScript using id.


In the following example we have an <h1> element that points to the id name “myHeader”. This <h1> element will be styled according to the #myHeader style definition in the head section,

See the Pen id in html by Arpit (@soniarpit) on CodePen.

We will learn about <style> tag in CSS tutorial.

id Syntax

In html tag,

<tagname id="id-name">...</tagname>

In css you just need to write hash(#) before id-name,


The id name is case sensitive.The id name must contain at least one character, and must not contain whitespaces (spaces, tabs, etc.).

We already learned in HTML links tutorial.

Difference between class and id

Image result for difference between class and id in html

Hope you enjoyed. Happy coding

Previous: #15 HTML class Attribute

Next: #17 HTML iFrame

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee
Your subscription could not be saved. Please try again.
Your subscription has been successful.


Subscribe to our newsletter and stay updated.

Leave a Comment