#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.

Example

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,

#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