সারাংশ
HTML <img>
এলিমেন্ট (বা HTML ইমেজ এলিমেন্ট) ডকুমেন্টের একটি ইমেজকে বোঝায়।
ব্যবহার নির্দেশিকাঃ
ব্রাউজার সবসময় এলিমেন্টের রেফারেন্স করা ছবি প্রদর্শন করে না। এটা নন-গ্রাফিক্যাল ব্রাউজারে (দৃষ্টি প্রতিবন্ধিদের ব্যবহারের গুলো সহ), অথবা যারা ছবি দেখতে চায় না, বা ছবিটির লিঙ্ক ভুল হওয়া বা অসমর্থিত ধরনের হওয়ার কারনে ব্রাউজার ছবিটি দেখাতে অক্ষম হতে পারে। এসব ক্ষেত্রে ব্রাউজার ছবিটিকে এলিমেন্টের alt অ্যাট্রিবিউটের মধ্যে থাকা টেক্সট প্রদর্শন করে।
- কনটেন্ট ক্যাটাগরি সমূহFlow content, phrasing content, embedded content, palpable content. যদি এলিমেন্টের একটি {{htmlattrxref("usemap", "img")}} অ্যাট্রিবিউট থাকে, তাহলে সেটাও ইন্টারেক্টিভ কনটেন্ট ক্যাটাগরির অংশ হবে।
- অনুমোদিত কনটেন্ট নেই, এটি একটি বাতিল এলিমেন্ট।
- Tag omission শুরুর ট্যাগ অবশ্যই থাকতে হবে এবং কোন শেষের ট্যাগ থাকা যাবেনা।
- অনুমোদিত parent এলিমেন্ট সমূহএম্বেডেড কনটেন্ট সমর্থন করে, এমন যেকোনো এলিমেন্ট।
- DOM ইন্টারফেস {{domxref("HTMLImageElement")}}
অ্যাট্রিবিউট সমূহ
এই এলিমেন্টের মধ্যে গ্লোবাল অ্যাট্রিবিউট সমূহ রয়েছে।
- {{htmlattrdef("align")}} {{deprecatedGeneric('inline','HTML4.01')}}, {{obsoleteGeneric('inline','HTML5')}} Use the {{cssxref('vertical-align')}} CSS property
- আশেপাশের অবস্থা অনুযায়ী ইমেজের অ্যালাইনমেন্ট
- {{htmlattrdef("alt")}}
-
এই অ্যাট্রিবিউট বিকল্প টেক্সট যেটি ছবিটিকে ব্যাখ্যা করে, তা বোঝায়। যদি ইমেজের লিঙ্ক ভুল হয়, সমর্থিত ফরম্যাটে না হয়, অথবা ইমেজ ডাউনলোড যদি শেষ না হয়, তবে ব্যবহারকারীরা এটি দেখবে।
Usage note: Omitting this attribute indicates that the image is a key part of the content, but no textual equivalent is available. Setting this attribute to the empty string indicates that this image is not a key part of the content; non-visual browsers may omit it from the rendering.
- {{htmlattrdef("border")}} {{deprecatedGeneric('inline','HTML4.01')}}, {{obsoleteGeneric('inline','HTML5')}}
- The width of a border around the image.
- {{htmlattrdef("crossorigin")}} {{HTMLVersionInline(5)}}
-
This enumerated attribute indicates if the fetching of the related image must be done using CORS or not. CORS-enabled images can be reused in the {{HTMLElement("canvas")}} element without being tainted. The allowed values are:
- anonymous
-
A cross-origin request (i.e. with
Origin:
HTTP header) is performed. But no credential is sent (i.e. no cookie, no X.509 certificate and no HTTP Basic authentication is sent). If the server does not give credentials to the origin site (by not setting theAccess-Control-Allow-Origin:
HTTP header), the image will be tainted and its usage restricted.. - use-credentials
-
A cross-origin request (i.e. with
Origin:
HTTP header) is performed with credential is sent (i.e. a cookie, a certificate and HTTP Basic authentication is performed). If the server does not give credentials to the origin site (throughAccess-Control-Allow-Credentials:
HTTP header), the image will be tainted and its usage restricted.
Origin:
HTTP header), preventing its non-tainted used in {{HTMLElement('canvas')}} elements. If invalid, it is handled as if the enumerated keyword anonymous was used. See CORS settings attributes for additional information. - {{htmlattrdef("height")}}
- The height of the image in {{HTMLVersionInline(5)}} CSS pixels, or {{HTMLVersionInline(4)}} in pixels or as a percentage.
- {{htmlattrdef("hspace")}} {{deprecatedGeneric('inline','HTML4.01')}}, {{obsoleteGeneric('inline','HTML5')}}
- The number of pixels of white space to insert to the left and right of the image.
- {{htmlattrdef("ismap")}}
-
This Boolean attribute indicates that the image is part of a server-side map. If so, the precise coordinates of a click are sent to the server.
Usage note: This attribute is allowed only if the
<img>
element is a descendant of an {{htmlelement("a")}} element with a valid {{htmlattrxref("href","a")}} attribute. - {{htmlattrdef("longdesc")}}{{HTMLVersionInline(4)}} only
- The URL of a description of the image to be displayed, which supplements the alt text. In {{HTMLVersionInline(5)}}, use a regular {{HTMLElement("a")}} element to link to the description.
- {{htmlattrdef("name")}} {{deprecatedGeneric('inline','HTML4.01')}}, {{obsoleteGeneric('inline','HTML5')}}
- A name for the element. It is supported in {{HTMLVersionInline(4)}} only for backward compatibility. Use the id attribute instead.
- {{htmlattrdef("src")}}
-
Image URL, this attribute is obligatory for the
<img>
element. - {{htmlattrdef("width")}}
- The width of the image in pixels or percent.
- {{htmlattrdef("usemap")}}
-
The partial URL (starting with '#') of an image map associated with the element.
Usage note: You cannot use this attribute if the
<img>
element is a descendant of an {{htmlelement("a")}} or {{HTMLElement("button")}} element. - {{htmlattrdef("vspace")}} {{deprecatedGeneric('inline','HTML4.01')}}, {{obsoleteGeneric('inline','HTML5')}}
- The number of pixels of white space to insert to above and below the image.
Supported image formats
The HTML standard doesn't give a list of image format that must be supported, so each user agent supports a different set of formats. Gecko supports:
- JPEG
- GIF, including animated GIFs
- PNG
- APNG {{gecko_minversion_inline("1.9.2")}}
- SVG {{gecko_minversion_inline("2.0")}}
- BMP
- BMP ICO
- PNG ICO {{gecko_minversion_inline("9.0")}}
Note:
Support for the XBM format has been removed in Gecko 1.9.2.
Interaction with CSS
Regarding CSS, an <img>
is a replaced element. It has no baseline, meaning that, when used in a inline formatting context with {{cssxref("vertical-align")}}: baseline
, the bottom of the image will be posed on the container's baseline.
An image may have an intrinsic dimension, but not necessarily, depending of its type. A SVG image has no intrinsic dimension, a raster image has one.
Example 1
<img src="https://developer.cdn.mozilla.net/media/img/mdn-logo-sm.png" alt="MD Logo" />
Example 2: Image link
<a href="https://developer.mozilla.org/" target="_blank"> <img src="https://developer.cdn.mozilla.net/media/img/mdn-logo-sm.png" alt="MDN Logo" /> </a>
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'embedded-content-1.html#the-img-element', '<img>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'embedded-content-0.html#the-img-element', '<img>')}} | {{Spec2('HTML5 W3C')}} | |
{{SpecName('HTML4.01', 'struct/objects.html#h-13.2', '<img>')}} | {{Spec2('HTML4.01')}} |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
See also
- {{HTMLElement("object")}} and {{HTMLElement("embed")}} elements