علامة <img> HTML


مثال

كيفية إدراج صورة:

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

المزيد من الأمثلة "جربها بنفسك" أدناه.


التعريف والاستخدام

تُستخدم <img>العلامة لتضمين صورة في صفحة HTML.

لا يتم إدراج الصور تقنيًا في صفحة الويب ؛ الصور مرتبطة بصفحات الويب. تنشئ <img>العلامة مساحة تعليق للصورة المشار إليها.

تحتوي <img>العلامة على سمتين مطلوبتين:

  • src - تحدد المسار إلى الصورة
  • بديل - يحدد نصًا بديلاً للصورة ، إذا تعذر عرض الصورة لسبب ما

ملاحظة: أيضًا ، حدد دائمًا عرض الصورة وارتفاعها. إذا لم يتم تحديد العرض والارتفاع ، فقد تومض الصفحة أثناء تحميل الصورة.

نصيحة: لربط صورة بمستند آخر ، ما عليك سوى دمج <img>العلامة داخل علامة (انظر المثال أدناه).


دعم المتصفح

Element
<img> Yes Yes Yes Yes Yes

صفات

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


السمات العالمية

تدعم <img>العلامة أيضًا السمات العامة في HTML .


سمات الحدث

تدعم <img>العلامة أيضًا سمات الحدث في HTML .


مزيد من الأمثلة

مثال

محاذاة الصورة (باستخدام CSS):

<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">

مثال

إضافة حدود الصورة (مع CSS):

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

مثال

أضف الهوامش اليمنى واليسرى للصورة (باستخدام CSS):

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

مثال

أضف الهوامش العلوية والسفلية للصورة (باستخدام CSS):

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

مثال

كيفية إدراج صور من مجلد آخر أو من موقع ويب آخر:

<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">

مثال

كيفية إضافة ارتباط تشعبي إلى صورة:

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

مثال

كيفية إنشاء خريطة صورة ، مع مناطق قابلة للنقر. كل منطقة عبارة عن ارتباط تشعبي:

<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>

الصفحات ذات الصلة

دروس HTML: صور HTML

مرجع DOM HTML: كائن الصورة

دروس CSS: تصفيف الصور


إعدادات CSS الافتراضية

ستعرض معظم المتصفحات <img>العنصر بالقيم الافتراضية التالية:

مثال

img {
  display: inline-block;
}