Images in HTML

Images in HTML web page ka design aur look better banate hain. Images in HTML ka use karke web pages ko zyada attractive aur informative banaya ja sakta hai.

Images in HTML


HTML Image Syntax

Images in HTML ko add karne ke liye <img> tag use kiya jata hai.

HTML Image Syntax

  • <img> tag image embed karta hai

  • Ye empty tag hota hai (closing tag nahi hota)

Isme 2 important attributes hote hain:

  • src → image ka path

  • alt → image ka alternate text


The src Attribute

Images in HTML me src attribute batata hai ki image kahan se load hogi.

Agar image nahi milti, to broken image icon aur alt text show hota hai.

The src Attribute


The alt Attribute

Images in HTML me alt attribute alternative text provide karta hai.

Alt text tab show hota hai jab:

  • Image load nahi hoti

  • Internet slow hota hai

  • Screen reader use kiya jata hai

Example:

The alt Attribute


Image Size (Width & Height)

Images in HTML me image ka size define karna important hota hai.

Style attribute se:

<img src=”img_boy.jpgalt=”Boy in jacketstyle=”width:500px;height:600px;”>

Direct attributes se:

<img src=”img_boy.jpgalt=”Boy in jacket” width =”500″ height =”600″>

Width aur height pixels me define hote hain.

Tip: Hamesha size specify karo, warna page load hote waqt layout flicker ho sakta hai.


Width/Height vs Style

Dono methods valid hain, lekin CSS style use karna better hota hai kyuki CSS se image size easily control kiya ja sakta hai.


Image in Another Folder

Images in HTML me image kisi aur folder se bhi load ki ja sakti hai.

<img src=”/imges/html5.gif” alt=”HTML5 Icon“>

Image from Another Website

External website se bhi Images in HTML load ki ja sakti hain.

<img src=”https://www.example.com/images/tree_green.jpg” alt=”Green Tree“>

Note: External images copyright issues create kar sakti hain aur kabhi bhi remove ho sakti hain.


Animated Images

Images in HTML me animation ke liye GIF images use ki ja sakti hain.

<img src=”programming.gif” alt=”Computer Manstyle=”width:48px;height:48px;”>


Image as Link

Images in HTML ko hyperlink ke roop me bhi use kiya ja sakta hai.

Example:

Image as Link

Image Floating

CSS float property se Images in HTML ko left ya right side par place kiya ja sakta hai.

Right side:

Image Floating Right SIde

Left side:

Image Floating Left Side

Common Image Formats

Abbreviation File Format Extension
APNG Animated Portable Network Graphics .apng
GIF Graphics Interchange Format .gif
ICO Microsoft Icon .ico
JPEG Joint Photographic Experts Group .jpg, .jpeg
PNG Portable Network Graphics .png
SVG Scalable Vector Graphics .svg

HTML Image Maps

Images in HTML me image maps ka use karke image par clickable areas bana sakte ho.

Image Maps

<map> tag ek image map define karta hai. Isme <area> elements ke through clickable regions define kiye jate hain.

Image

Image ko <img> tag se insert kiya jata hai aur usemap attribute add kiya jata hai.

Example:

HTML Image Maps

usemap ki value # se start hoti hai aur image map ka naam batati hai.


Image Map Create Karna

<map> element image map banane ke liye use hota hai.

Image Map Create Karna

name attribute ki value same honi chahiye jo <img> ke usemap attribute me hai.


Areas

Clickable areas <area> element se define hote hain.


Shape

Clickable area ka shape define karna zaroori hota hai.

Possible values:

  • rect → rectangular area

  • circle → circular area

  • poly → polygon area

  • default → poora region

Coordinates define karke clickable area ko image par place kiya jata hai.

Shape=”rect”

rect ke coordinates pairs me hote hain, ek x-axis ke liye aur ek y-axis ke liye.

Coordinates 34,44 ka matlab hai left margin se 34 pixels aur top se 44 pixels. Coordinates 270,350 ka matlab hai left se 270 pixels aur top se 350 pixels. Ab rectangle clickable area banane ke liye:

Shape="rect"


Image Map and JavaScript

Images in HTML me clickable areas JavaScript functions bhi trigger kar sakte hain. <area> element me click event add karke JavaScript function execute kar sakte ho:

Example:

Image Map and JavaScript


HTML Background Images

Images in HTML ko background ke roop me bhi use kiya ja sakta hai.


Background Image on an HTML Element

HTML element par background image add karne ke liye style attribute aur CSS background-image property use karo.

Example:

Background Image on an HTML Element

Aap <head> section ke andar <style> element me bhi background image specify kar sakte ho.

HTML Background Images


Background Image on a Page

Agar poori page par background image lagani ho to <body> element par specify karte hain.

Example:

Background Image on a Page


Background Repeat

Agar background image element se chhoti hai, to image horizontal aur vertical dono direction me repeat hogi jab tak element ka end na aa jaye.

Example:

Background Repeat

Repeat rokne ke liye background-repeat property ko no-repeat set karo.

Example:

Repeat rokne ke liye


Background Cover

Agar image ko poora element cover karna ho:

background-size: cover;
background-attachment: fixed;

Example:

Background Cover

Isse image stretch nahi hoti aur proportion maintain rehta hai.


Background Stretch

Image ko poore element me stretch karne ke liye:

background-size: 100% 100%;

Browser window resize karne par image stretch hogi aur hamesha poora element cover karegi.

Example:

Background Stretch

HTML <picture> Element

Images in HTML me <picture> element different devices ke liye different images show karne ke liye use hota hai.

<picture> element ke andar ek ya zyada <source> elements hote hain.

 Har <source> me <srcset>attribute ke through different image di jaati hai. Is tarah browser current screen ya device ke hisaab se best image choose karta hai.

Har <source> element me <media> attribute hota hai jo define karta hai ki image kab suitable hogi.

Example:

HTML <picture> Element

Note: <picture> ke andar last me <img> element zaroor hona chahiye.


When to Use <picture> Element

Images in HTML me <picture> element do main reasons ke liye use hota hai:

1. Bandwidth

Chhoti screen par badi image load karne ki zaroorat nahi hoti, isliye browser appropriate image choose karta hai.

2. Format Support

Alag browsers different image formats support karte hain. <picture> element multiple formats define karne ki flexibility deta hai.

Example:

Browser pehla recognize hone wala format use karega:

When to use <picture> Element

Note: Browser pehla matching <source> element use karta hai aur uske baad wale <source> elements ignore kar deta hai.


Is tarah Images in HTML web pages ko visually attractive banate hain aur developers ko images ko display, style aur control karne ke multiple flexible options provide karte hain.

Leave a Comment