HTML <img> Etiketi


Örnek

Bir resim nasıl eklenir:

<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600">

Aşağıda daha fazla "Kendiniz Deneyin" örnekleri.


Tanım ve Kullanım

<img>etiketi, bir HTML sayfasına bir resim gömmek için kullanılır .

Görüntüler teknik olarak bir web sayfasına eklenmez; resimler web sayfalarına bağlıdır. <img>etiketi, başvurulan görüntü için bir tutma alanı oluşturur .

Etiketin <img>iki gerekli özelliği vardır:

  • src - Resmin yolunu belirtir
  • alt - Resim herhangi bir nedenle görüntülenemiyorsa, resim için alternatif bir metin belirtir

Not: Ayrıca, her zaman bir görüntünün genişliğini ve yüksekliğini belirtin. Genişlik ve yükseklik belirtilmezse, resim yüklenirken sayfa titreyebilir.

İpucu: Bir görüntüyü başka bir belgeye bağlamak için etiketi bir <a><img> etiketinin içine yerleştirmeniz yeterlidir (aşağıdaki örneğe bakın).


Tarayıcı Desteği

Element
<img> Yes Yes Yes Yes Yes

Öznitellikler

Attribute Value Description
alt text Specifies an alternate text for an image
crossorigin anonymous
use-credentials
Allow images from third-party sites that allow cross-origin access to be used with canvas
height pixels Specifies the height of an image
ismap ismap Specifies an image as a server-side image map
loading eager
lazy
Specifies whether a browser should load an image immediately or to defer loading of images until some conditions are met
longdesc URL Specifies a URL to a detailed description of an image
referrerpolicy no-referrer
no-referrer-when-downgrade
origin
origin-when-cross-origin
unsafe-url
Specifies which referrer information to use when fetching an image
sizes sizes Specifies image sizes for different page layouts
src URL Specifies the path to the image
srcset URL-list Specifies a list of image files to use in different situations
usemap #mapname Specifies an image as a client-side image map
width pixels Specifies the width of an image


Genel Özellikler

Etiket ayrıca HTML'deki Global Nitelikleri<img> de destekler .


Etkinlik Özellikleri

Etiket ayrıca HTML'deki Etkinlik Niteliklerini<img> de destekler .


Daha fazla örnek

Örnek

Resmi hizala (CSS ile):

<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="vertical-align:bottom">
<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="vertical-align:middle">
<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="vertical-align:top">
<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="float:right">
<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="float:left">

Örnek

Resim kenarlığı ekle (CSS ile):

<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="border:5px solid black">

Örnek

Görüntüye sol ve sağ kenar boşlukları ekleyin (CSS ile):

<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="vertical-align:middle;margin:0px 50px">

Örnek

Görüntüye üst ve alt kenar boşlukları ekleyin (CSS ile):

<img src="smiley.gif" alt="Smiley face" width="42" height="42" style="vertical-align:middle;margin:50px 0px">

Örnek

Başka bir klasörden veya başka bir web sitesinden resimler nasıl eklenir:

<img src="/images/stickman.gif" alt="Stickman" width="24" height="39">
<img src="https://www.w3schools.com/images/lamp.jpg" alt="Lamp" width="32" height="32">

Örnek

Bir resme köprü nasıl eklenir:

<a href="https://www.w3schools.com">
<img src="w3html.gif" alt="W3Schools.com" width="100" height="132">
</a>

Örnek

Tıklanabilir bölgelerle bir resim haritası nasıl oluşturulur. Her bölge bir köprüdür:

<img src="workplace.jpg" alt="Workplace" usemap="#workmap" width="400" height="379">

<map name="workmap">
  <area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
  <area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
  <area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm">
</map>

İlgili Sayfalar

HTML eğitimi: HTML Görselleri

HTML DOM referansı: Resim Nesnesi

CSS Eğitimi: Şekillendirme Görüntüleri


Varsayılan CSS Ayarları

Çoğu tarayıcı, <img>öğeyi aşağıdaki varsayılan değerlerle görüntüler:

Örnek

img {
  display: inline-block;
}