HTML ID Attribute In Hindi – ID Attribute In HTML In Hindi ?

HTML

HTML ID Attribute In Hindi – What Is The Use Of ID Attribute In HTML In Hindi? – Kisi Bhi HTML Element Ko Unique Id Dene Ke Liye Hum ID Attribute Ka Istemaal Karte Hain.

HTML ID Attribute In Hindi

How To Use The ID Attribute In HTML Tags? Jaise Ki Class Attribute Hota Hai, Ussi Tareeke Se Har HTML Tag/ Element Ka ID Attribute Bhi Hota Hai Lekin Dono Attributes Me Bhot Difference Hota Hai. Aaiye Kuch Important Points Ki Sahayata Se Samjhe Ki ID Attribute Kyu Istemal Kiya Jata Hai Aur Class Aur ID Attribute Me Kya Difference Hai:

  • Kisi Bhi HTML Element Ko Unique Id Dene Ke Liye Hum ID Attribute Ka Istemal Karte Hain.
  • Kisi Bhi HTML Tag/ Element Ki ID Attribute Ki Value Pure HTML Document Mein Unique Hoti Hai, Ek Se Jyada Tags Ko Same Id Dena Allowed Nahi Hai.
  • ID Attribute Ka Istemal HTML Document Mein Bookmark Create Karne Ke Liye Bhi Kiya Ja Sakta Hai.
  • CSS Me Kisi Specific Element Par Styles Apply Karne Ke Liye ID Attribute Ka Istemaal Kiya Jata Hai.
  • JavaScript Me Bhi ID Attribute Ke Jariye Hi Kisi Specific Element Ko Access Ya Manipulate Kiya Jata Hai, getElementById() Method Ki Help Se.

Also Read – HTML Classes

Using The ID Attribute

HTML Mein Har Element Ke Sath Hum Id Attribute Ko Istemaal Kar Sakte Hain, Lekin Usko Istemaal Karne Se Pehle Syntax Ke Kuch Important Points Ke Bare Me Jaan Lete Hain:

  • ID Attributes Ki Value Case-Sensitive Hoti Hai.
  • ID Attribute Ki Value Ke Liye Atleast Ek Character Zaroor Istemaal Karna Hota Hai.
  • ID Attribute Ki Value Ke Liye White Spaces (Spaces, Tabs, Etc.) Istemaal Nahi Kar Sakte.
  • CSS Me Style Properties Ko Define Karne Ke Liye Hum Following Syntax Ka Istemaal Karte Hain:

ID Ko CSS Style Me Istemal Karne Ke Liye # Ka IStemal Kiya Jata Hai.

Syntax:

#id_name{
	 css Propertites
...
..
}

Aaiye Ab Ek Simple Example Ke Jariye Samajhte Hain Ki Kis Tareeke Se ID Attribute Ko Istemaal Kiya Jata Hai:

Example:

<!DOCTYPE html>
<html>
<head>
<style>
#myHeader {
  background-color: lightblue;
  color: black;
  padding: 40px;
  text-align: center;
}
</style>
</head>
<body>

<h1 id="myHeader">My Header</h1>

</body>
</html>

Output:

Explanation:

Upar Diye Gaye Example Mein <h1> Tag “myHeader” Id Ko Point Kar Rahi Hai Aur <h1> Element  #myHeader Style Section Mein Di Gayi Style Properties Ke According Style Ho Gaya Hai.

What Is The Difference Between Class And ID Attribute In HTML?

HTML Ke Tags/ Elements Mein class Name Ko Hum Ek Se Jyada Elements Ke Liye Istemaal Kar Sakte Hain Lekin ID Kewal Ek Element Ke Liye Hi Istemaal Ki Jati Hai. Aaiye Ek Example Ki Sahayata Se Dono Ke Beech Ka Difference Samajhte Hain:

Example:

<!DOCTYPE html>
<html>
<head>
<style>
/* Style the element with the id "myHeader" */
#myHeader {
  background-color: lightblue;
  color: black;
  padding: 40px;
  text-align: center;
}

/* Style all elements with the class name "city" */
.city {
  background-color: tomato;
  color: white;
  padding: 10px;
} 
</style>
</head>
<body>

<h2>Difference Between Class and ID</h2>
<p>A class name can be used by multiple HTML elements, while an id name must only be used by one HTML element within the page:</p>

<!-- An element with a unique id -->
<h1 id="myHeader">My Cities</h1>

<!-- Multiple elements with same class -->
<h2 class="city">London</h2>
<p>London is the capital of England.</p>

<h2 class="city">Paris</h2>
<p>Paris is the capital of France.</p>

<h2 class="city">Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>

</body>
</html>


Output:

Explanation:

Upar Diye Gaye Example Me .city Naam Se Ek class Define Ki Gayi Hai Aur #myHeader Naam Se Ek Element Ki id Define Ki Gayi Hai.

Ek <h1> Mein #myHeader id Ki Style Properties Apply Ho Gayi Hain Aur teen <h2> Elements Mein .city class Ki Style Properties Apply Ho Gayi Hain.

Leave a Reply

Your email address will not be published. Required fields are marked *