Attributes in HTML

Attributes in HTML, elements ko extra information dete hain.

HTML Attributes

  • Har elements in HTML ke paas attributes ho sakte hain.
  • Attributes in HTML element ke baare me extra info dete hain.
  • Attributes hamesha start tag me likhe jaate hain.
  • Attributes usually name/value pair me hote hain, jaise:
    name=”value”.

The href Attribute

<a> tag hyperlink define karta hai. href attribute batata hai ki link kis URL par jayega.

<a href=https://www.google.com“>Visit Google </a>


The src Attribute

<img> tag image ko page me show karne ke liye use hota hai. src attribute image ka path batata hai.

Attributes in HTML

 

URL specify karne ki 2 types hote hai.

1. Absolute URL

Dusri website par hosted image ka full link.

Example:
src=”https://www.example.com/images/img_girl.jpg

Note: External images copyright ke under ho sakti hain. Permission ke bina use karna galat ho sakta hai. Aur external image kabhi bhi remove ya change ho sakti hai.

2. Relative URL

Apni website ke andar wali image ka link.

Example:
src=”img_girl.jpg

Agar slash se start hota hai:
src=”/images/img_girl.jpg”

Tip: Relative URL use karna best hota hai. Domain change hone par bhi link break nahi hota.


The width aur height Attributes

alt attribute required hota hai <img> ke liye. Agar image load nahi hoti (slow internet, galat src, ya screen reader use ho raha ho), toh alt text show hota hai. Also, agar image exist hi nahi karti toh bhi alt text show karti hai.

Example:

The width aur height Attributes


The style Attribute

style attribute element me styling add karne ke liye use hota hai, jaise color, font, size, etc.

The style Attribute


The lang Attribute

<html> tag ke andar lang attribute likhna chahiye. Yeh batata hai page kis language me hai.

Example (English)

The lang Attribute


The title Attribute

title attribute element ke baare me extra info deta hai. Mouse hover karne par tooltip ke form me show hota hai.

Example:

<p title= “Mey tooltip hu” > This is a paragraph. </p>


Hamesha Lowercase Attributes Use Karein

HTML me uppercase ya lowercase dono chal sakta hai. Par har jagah lowercase recommend karta hai. Isliye generally lowercase hi use karna chahiye.


Attribute Values Hamesha Quotes Me Likho

HTML me quotes compulsory nahi hain, lekin standard recommend karta hai ki quotes use karein.


Single or Double Quotes?

HTML me double quotes zyada common hain. Single quotes bhi use kar sakte ho.

Agar value ke andar double quotes ho, toh single quotes use karo:

Single Quotes

Ya agar single quotes ho, toh double quotes use karo:

Double Quotes

Leave a Comment