id-attribute-html

ID, at the present time it's an identity of a person or thing or a digital product. But In html5 id have an attitude who used to set a unique name for a tag in a web document. Give a name to element is important for it with a style sheet, a web link or a scripting language. When give value to id, that important, it's beginning with a letter (A-Z or A-Z) and may be followed by any number of letter, digits, hyphen or period.
It's value not contain whitespace that must same time user not understand how the class and id different, so a class can be used by multiple element and give two or more value in one class name but id attitude only be used by one element with only one value in one webpage. It's case sensitive it means Kingdom and kingdom have two different id value.


Syntax :

<tag id="value">content</tag>


Example

Note: In this following example, we give id name "main" to the <div> element.



Important :



ID Attribute Use In CSS As Selector :

The id attribute make easy to give style and color in html elements. A user can access an element directly by its id name. Using a id value name for styling in CSS, first write a hash character (#) and second write an id value (example: #value). Then define the CSS properties under curly braces {}.


Example



ID Attribute Use In JavaScript :

In scripting language, it's purpose is to identify the HTML element when given a command or manipulate text. JavaScript can access an element to its id with the DOM (Document Object Model) method getElementsById().

Example



Give Bookmark In Html With Id Attribute And Link :

The id attribute is used to in making a bookmark. Normally bookmark are used to go or find a specific element part of on a web page. It's most useful when a web page became very large. If a developer wants to create a bookmark first important that create a bookmark with the id attribute then add a link to the bookmark. In This link the HREF attribute value first start with a hash character (#) then write the value name ("#idname"). This link is a way, when a user click on this link thay go to on main content where have given id attribute value.


Example