--- title: HTMLImageElement slug: Web/API/HTMLImageElement translation_of: Web/API/HTMLImageElement --- <div>{{ApiRef}}</div> <div>{{APIRef("HTML DOM")}}</div> <p>Интерфейс <code><strong>HTMLImageElement</strong></code> предоставляет специальные свойства и методы (расширяя обычный интерфейс {{domxref("HTMLElement")}} ) для управления вёрсткой и отображением элемента {{HTMLElement("img")}}. </p> <p>{{InheritanceDiagram(600,120)}} </p> <h2 id="Свойства">Свойства</h2> <p><em>Наследует свойства родителя, {{domxref("HTMLElement")}}.</em></p> <table class="standard-table"> <thead> <tr> <th scope="col">Имя</th> <th scope="col">Тип</th> <th scope="col">Описание</th> </tr> </thead> <tbody> <tr> <td><code>align</code> {{obsolete_inline}}</td> <td>{{domxref("DOMString")}}</td> <td>Указывает расположение картинки зависящее от окружающего контента. Возможные значения: <code>"left"</code>, <code>"right"</code>, <code>"justify"</code>, и <code>"center"</code>.</td> </tr> <tr> <td><code>alt</code></td> <td>{{domxref("DOMString")}}</td> <td>Повторяет атрибут HTML {{htmlattrxref("alt", "img")}} указывающий на запасной контекст картинки.</td> </tr> <tr> <td><code>border</code> {{obsolete_inline}}</td> <td>{{domxref("DOMString")}}</td> <td>Ширина рамки вокруг картинки. Устарело и вместо него следует использовать свойство CSS {{cssxref("border")}}.</td> </tr> <tr> <td><code>complete</code> {{readonlyInline}}</td> <td>{{domxref("Boolean")}}</td> <td>Возвращает true, если браузер закончил загрузку картинки с ошибкой или успешно. Также возвращает true, когда не установлено значение {{domxref("HTMLImageElement.src", "src")}}, во всех остальных случаях - false.</td> </tr> <tr> <td><code>crossOrigin</code></td> <td>{{domxref("DOMString")}}</td> <td>Является {{domxref("DOMString")}}, с настройками CORS для этого элемента изображения. Дополнительная информация: <a href="https://developer.mozilla.org/en-US/docs/HTML/CORS_settings_attributes">Атрибуты настроек CORS</a>. </td> </tr> <tr> <td><code>currentSrc</code>{{readonlyInline}}{{experimental_inline}}</td> <td>{{domxref("DOMString")}}</td> <td>Возвращает {{domxref("DOMString")}} с URL-адресом текущего изображения (что может измениться, например, в ответ на запросы мультимедиа).</td> </tr> <tr> <td><code>height</code></td> <td><code>unsigned long</code></td> <td>Отражает атрибут {{htmlattrxref ("height", "img")}} HTML, указывая визуализированную высоту изображения в пикселях CSS.</td> </tr> <tr> <td><code>hspace</code> {{obsolete_inline}}</td> <td><code>long</code></td> <td>Space to the left and right of the image.</td> </tr> <tr> <td><code>isMap</code></td> <td>{{domxref("Boolean")}}</td> <td>Reflects the {{htmlattrxref("ismap", "img")}} HTML attribute, indicating that the image is part of a server-side image map.</td> </tr> <tr> <td><code>longDesc</code> {{obsolete_inline}}</td> <td>{{domxref("DOMString")}}</td> <td>URI of a long description of the image.</td> </tr> <tr> <td><code>lowSrc</code> {{obsolete_inline}}</td> <td>{{domxref("DOMString")}}</td> <td>A reference to a low-quality (but faster to load) copy of the image.</td> </tr> <tr> <td><code>name</code> {{obsolete_inline}}</td> <td>{{domxref("DOMString")}}</td> <td> </td> </tr> <tr> <td><code>naturalHeight</code> {{readonlyInline}}</td> <td><code>unsigned long</code></td> <td>Intrinsic height of the image in CSS pixels, if it is available; otherwise, <code>0</code>.</td> </tr> <tr> <td><code>naturalWidth</code> {{readonlyInline}}</td> <td><code>unsigned long</code></td> <td>Intrinsic width of the image in CSS pixels, if it is available; otherwise, <code>0</code>.</td> </tr> <tr> <td><code>src</code></td> <td>{{domxref("DOMString")}}</td> <td>Reflects the {{htmlattrxref("src")}} HTML attribute, containing the URL of the image.</td> </tr> <tr> <td><code>srcset</code> {{experimental_inline}}</td> <td> </td> <td> </td> </tr> <tr> <td><code>useMap</code></td> <td>{{domxref("DOMString")}}</td> <td>Reflects the {{htmlattrxref("usemap", "img")}} HTML attribute, containing a partial URL of a map element.</td> </tr> <tr> <td><code>vspace</code> {{obsolete_inline}}</td> <td><code>long</code></td> <td>Space above and below the image.</td> </tr> <tr> <td><code>width</code></td> <td><code>unsigned long</code></td> <td>Reflects the {{htmlattrxref("width", "img")}} HTML attribute, indicating the rendered width of the image in CSS pixels.</td> </tr> <tr> <td><code>x</code> {{readonlyInline}}{{non-standard_inline}}</td> <td><code>long</code></td> <td>The horizontal offset from the nearest layer. (Mimic an old Netscape 4 behavior)</td> </tr> <tr> <td><code>y</code> {{readonlyInline}}{{non-standard_inline}}</td> <td><code>long</code></td> <td>The vertical offset from the nearest layer. (Mimic an old Netscape 4 behavior)</td> </tr> </tbody> </table> <h2 id="Методы">Методы</h2> <p><em>Наследует методы родителя, {{domxref("HTMLElement")}}.</em></p> <dl> <dt>{{domxref("HTMLImageElement.Image()")}}</dt> <dd>The <code>Image()</code> constructor, taking two optional <code>unsigned</code> <code>long</code>, the width and the height of the resource, creates an instance of <code>HTMLImageElement</code> not inserted in a DOM tree.</dd> </dl> <h2 id="Пример">Пример</h2> <pre class="brush: js">var img1 = new Image(); // Конструктор HTML5 img1.src = 'image1.png'; img1.alt = 'alt'; document.body.appendChild(img1); var img2 = document.createElement('img'); // Используем <a href="http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/html/nsIDOMHTMLImageElement.idl" title="http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/html/nsIDOMHTMLImageElement.idl">HTMLImageElement</a> img2.src = 'image2.jpg'; img2.alt = 'alt text'; document.body.appendChild(img2); // выбираем первое изображение на странице alert(document.images[0].src); </pre> <h2 id="Спецификации">Спецификации</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Спецификация</th> <th scope="col">Статус</th> <th scope="col">Комментарий</th> </tr> <tr> <td>{{SpecName('HTML WHATWG', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}</td> <td>{{Spec2('HTML WHATWG')}}</td> <td>The following property has been added: <code>srcset</code>.</td> </tr> <tr> <td>{{SpecName('HTML5 W3C', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}</td> <td>{{Spec2('HTML5 W3C')}}</td> <td>A constructor (with 2 optional parameters) has been added.<br> The following properties are now obsolete: <code>name</code>, <code>border</code>, <code>align</code>, <code>hspace</code>, <code>vspace</code>, and <code>longdesc</code>.<br> The following properties are now <code>unsigned long</code>, instead of <code>long</code>: <code>height</code>, and <code>width</code>.<br> The following properties have been added: <code>crossorigin</code>, <code>naturalWidth</code>, <code>naturalHeight</code>, and <code>complete</code>.</td> </tr> <tr> <td>{{SpecName('DOM2 HTML', 'html.html#ID-17701901', 'HTMLImgElement')}}</td> <td>{{Spec2('DOM2 HTML')}}</td> <td>The <code>lowSrc</code> property has been removed.<br> The following properties are now <code>long</code>, instead of <code>DOMString</code>: <code>height</code>, <code>width</code>, <code>hspace</code>, and <code>vspace</code>.</td> </tr> <tr> <td>{{SpecName('DOM1', 'level-one-html.html#ID-17701901', 'HTMLImgElement')}}</td> <td>{{Spec2('DOM1')}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <h2 id="Совместимость">Совместимость</h2> <p>{{Compat}}</p> <h2 id="Смотрите_также">Смотрите также</h2> <ul> <li>Элемент HTML, реализующий этот интерфейс: {{HTMLElement("img")}}</li> </ul>