이 번역은 완료되지 않았습니다. 이 문서를 번역해 주세요.

HTML <img> 요소는 문서에 이미지를 넣습니다.

The above example shows very simple usage of the <img> element. The src attribute is required, and contains the path to the image you want to embed. The alt attribute contains a textual description of the image, which isn't mandatory but is incredibly useful for accessibility — screenreaders read this description out to their users so they know what the image shows, and it is also displayed on the page if the image can't be loaded for some reason.

There are many other attributes that can be specified to achieve various purposes, for example:

  • Referrer/CORS control for security purposes; see crossorigin and referrerpolicy.
  • Setting of an intrinsic size using width and height, which is useful when you want to set the space taken up by an image to ensure the page layout is stable before it loads.
  • Responsive image hints using sizes and srcset (see also the <picture> element, and our Responsive images tutorial).

지원하는 이미지 포맷

HTML 표준은 지원해야 하는 이미지 형식을 명시하고 있지 않습니다. 따라서 각각의 사용자 에이전트는 다른 형식을 지원합니다.

Firefox

Firefox가 지원하는 이미지 형식은 다음과 같습니다.

이미지를 가져올 수 없을 때

이미지를 불러오거나 그릴 때 오류가 발생했고, onerror 속성에 오류 처리기를 등록했다면 error 이벤트와 함께 처리기를 호출합니다. 오류는 다양한 상황에서 발생할 수 있는데, 그 중 일부 원인은 다음과 같습니다.

  • src 속성이 비었거나 null임.
  • src의 URL이 현재 사용자가 보는 페이지의 URL과 같음.
  • 지정한 이미지가 손상돼 불러올 수 없음.
  • 이미지의 메타데이터가 손상돼 원본 크기를 알아낼 수 없고, <img> 요소의 속성에도 크기를 지정하지 않음.
  • 사용자 에이전트가 지원하지 않는 이미지 형식임.

속성

이 요소는 전역 속성을 포함합니다.

alt
This attribute defines an alternative text description of the image.

Note: Browsers do not always display the image referenced by the element. This is the case for non-graphical browsers (including those used by people with visual impairments), if the user chooses not to display images, or if the browser cannot display the image because it is invalid or an unsupported type. In these cases, the browser may replace the image with the text defined in this element's alt attribute. You should, for these reasons and others, provide a useful value for alt whenever possible.

Note: Omitting this attribute altogether indicates that the image is a key part of the content, and no textual equivalent is available. Setting this attribute to an empty string (alt="") indicates that this image is not a key part of the content (decorative), and that non-visual browsers may omit it from rendering.

crossorigin
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 <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, X.509 certificate, or HTTP Basic authentication). If the server does not give credentials to the origin site (by not setting the Access-Control-Allow-Origin HTTP header), the image will be tainted and its usage restricted.
use-credentials
A cross-origin request (i.e., with the Origin HTTP header) performed along with credentials sent (i.e., a cookie, certificate, or HTTP Basic authentication). If the server does not give credentials to the origin site (through the Access-Control-Allow-Credentials HTTP header), the image will be tainted and its usage restricted.
If the attribute is not present, the resource is fetched without a CORS request (i.e., without sending the Origin HTTP header), preventing its non-tainted usage in <canvas> elements. If invalid, it is handled as if the anonymous value was used. See CORS settings attributes for additional information.
decoding

Provides an image decoding hint to the browser. The allowed values are:

sync
Decode the image synchronously for atomic presentation with other content.
async
Decode the image asynchronously to reduce delay in presenting other content.
auto
Default mode, which indicates no preference for the decoding mode. The browser decides what is best for the user.
height
The intrinsic height of the image in pixels.
importance
Indicates the relative importance of the resource. Priority hints are delegated using the values:

auto: Indicates no preference. The browser may use its own heuristics to decide the priority of the image.

high: Indicates to the browser that the image is of high priority.

low: Indicates to the browser that the image is of low priority.

intrinsicsize
This attribute tells the browser to ignore the actual intrinsic size of the image and pretend it’s the size specified in the attribute. Specifically, the image would raster at these dimensions and naturalWidth/naturalHeight on images would return the values specified in this attribute. Explainer, examples
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.

Note: This attribute is allowed only if the <img> element is a descendant of an <a> element with a valid href attribute.

referrerpolicy
A string indicating which referrer to use when fetching the resource:
  • no-referrer: The Referer header will not be sent.
  • no-referrer-when-downgrade: No Referer header will be sent when navigating to an origin without TLS (HTTPS). This is a user agent’s default behavior if no policy is otherwise specified.
  • origin: The Referer header will include the page of origin's scheme, the host, and the port.
  • origin-when-cross-origin: Navigating to other origins will limit the included referral data to the scheme, the host and the port, while navigating from the same origin will include the referrer's full path.
  • unsafe-url: The Referer header will include the origin and the path, but not the fragment, password, or username. This case is unsafe because it can leak origins and paths from TLS-protected resources to insecure origins.
sizes
A list of one or more strings separated by commas indicating a set of source sizes. Each source size consists of:
  1. a media condition. This must be omitted for the last item.
  2. a source size value.

Source size values specify the intended display size of the image. User agents use the current source size to select one of the sources supplied by the srcset attribute, when those sources are described using width ('w') descriptors. The selected source size affects the intrinsic size of the image (the image’s display size if no CSS styling is applied). If the srcset attribute is absent, or contains no values with a width (w) descriptor, then the sizes attribute has no effect.

src
The image URL. This attribute is mandatory for the <img> element. On browsers supporting srcset, src is treated like a candidate image with a pixel density descriptor 1x unless an image with this pixel density descriptor is already defined in srcset, or unless srcset contains 'w' descriptors.
srcset
A list of one or more strings separated by commas indicating a set of possible image sources for the user agent to use. Each string is composed of:
  1. a URL to an image,
  2. optionally, whitespace followed by one of:
    • A width descriptor, or a positive integer directly followed by 'w'. The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density.
    • A pixel density descriptor, which is a positive floating point number directly followed by 'x'.

If no descriptor is specified, the source is assigned the default descriptor: 1x.

It is incorrect to mix width descriptors and pixel density descriptors in the same srcset attribute. Duplicate descriptors (for instance, two sources in the same srcset which are both described with '2x') are also invalid.

The user agent selects any one of the available sources at its discretion. This provides them with significant leeway to tailor their selection based on things like user preferences or bandwidth conditions. See our Responsive images tutorial for an example.

width
The intrinsic width of the image in pixels.
usemap
The partial URL (starting with '#') of an image map associated with the element.

Note: You cannot use this attribute if the <img> element is a descendant of an <a> or <button> element.

CSS와 상호작용하기

Regarding CSS, an <img> is a replaced element. It has no baseline, so when images are used in an inline formatting context with vertical-align: baseline, the bottom of the image will be posed on the container's baseline.

Depending on its type, an image may have an intrinsic width and height, but will not necessarily have them. For instance, SVG images have no intrinsic dimensions.

예제

보조 텍스트

The following simple example embeds an image into the page, and includes alternative text to improve accessibility.

<img src="https://developer.cdn.mozilla.net/media/img/mdn-logo-sm.png"
     alt="MDN logo — a dinosaur logo with the text MDN">

이미지 링크

This example builds upon the previous one, showing how to turn the image into a link. It is very simple to do so — you just nest the <img> tag inside the <a>. One consideration is that you should made the alternative text describe the resource the link is pointing to.

<a href="https://developer.mozilla.org">
  <img src="https://developer.cdn.mozilla.net/media/img/mdn-logo-sm.png"
       alt="Visit the MDN site">
</a>

srcset 속성 사용하기

In this example we include a srcset attribute containing a reference to a high-resolution version of the logo; this will be loaded instead of the src image on high-resolution devices. The image referenced in the src attribute is counted as a 1x candidate in user agents that support srcset.

 <img src="mdn-logo-sm.png" 
      alt="MDN" 
      srcset="mdn-logo-HD.png 2x">

srcset과 sizes 속성 사용하기

The src attribute is ignored in user agents that support srcset when 'w' descriptors are included. When the (max-width: 600px) media condition matches, the 200px wide image will be loaded (it is the one that matches 200px most closely), otherwise the other image will be loaded.

 <img src="clock-demo-thumb-200.png" 
      alt="Clock" 
      srcset="clock-demo-thumb-200.png 200w,
          clock-demo-thumb-400.png 400w"
      sizes="(max-width: 600px) 200px, 50vw">

명세

명세 상태 주석
HTML Living Standard
The definition of '<img>' in that specification.
Living Standard  
HTML5
The definition of '<img>' in that specification.
Recommendation  
HTML 4.01 Specification
The definition of '<img>' in that specification.
Recommendation  

브라우저 호환성

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
imgChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
align
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
altChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
border
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
crossoriginChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
decodingChrome Full support YesEdge ? Firefox Full support 63IE No support NoOpera Full support YesSafari No support NoWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 63Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
heightChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
hspace
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
intrinsicsize
ExperimentalNon-standard
Chrome Full support 71
Disabled
Full support 71
Disabled
Disabled From version 71: this feature is behind the #enable-experimental-productivity-features preference. To change preferences in Chrome, visit chrome://flags.
Edge ? Firefox ? IE No support NoOpera Full support 58Safari No support NoWebView Android Full support 71
Disabled
Full support 71
Disabled
Disabled From version 71: this feature is behind the #enable-experimental-productivity-features preference.
Chrome Android Full support 71
Disabled
Full support 71
Disabled
Disabled From version 71: this feature is behind the #enable-experimental-productivity-features preference. To change preferences in Chrome, visit chrome://flags.
Edge Mobile ? Firefox Android ? Opera Android Full support 58Safari iOS No support NoSamsung Internet Android ?
ismapChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
longdescChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
name
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onerror
Deprecated
Chrome Full support YesEdge ? Firefox Full support 51IE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 51Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
referrerpolicyChrome Full support 51Edge No support NoFirefox Full support 50IE No support NoOpera Full support 38Safari Full support 11.1WebView Android Full support 51Chrome Android Full support 51Edge Mobile No support NoFirefox Android Full support 50Opera Android Full support 38Safari iOS No support NoSamsung Internet Android Full support 7.2
sizesChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
srcChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
srcsetChrome Full support 34Edge Full support YesFirefox Full support 38
Full support 38
No support 32 — 52
Disabled
Disabled From version 32 until version 52 (exclusive): this feature is behind the dom.image.srcset.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 21Safari Full support 8WebView Android Full support 37Chrome Android Full support 34Edge Mobile Full support YesFirefox Android Full support 38
Full support 38
No support 32 — 52
Disabled
Disabled From version 32 until version 52 (exclusive): this feature is behind the dom.image.srcset.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 21Safari iOS Full support 8Samsung Internet Android Full support Yes
usemapChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
vspace
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
widthChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
User must explicitly enable this feature.
User must explicitly enable this feature.

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: mdnwebdocs-bot, alattalatta, azunyan3
최종 변경자: mdnwebdocs-bot,