background-image CSS 속성은 요소의 배경 이미지를 한 개나 여러 개 지정합니다.

여러 개의 배경 이미지는 쌓임 맥락에 따라 서로의 위에 놓입니다. 맨 처음 지정한 이미지가 제일 위에(사용자에게 제일 가까운 것 처럼) 위치합니다.

테두리는 배경 이미지 위에, background-color는 밑에 그려집니다. 요소 박스와 테두리에 관련하여 배경 이미지를 어떻게 그릴지는 background-clipbackground-origin CSS 속성이 정의합니다.

유효하지 않은 URI처럼 어떤 이유로 지정한 이미지를 그릴 수 없을 때는 none 키워드를 사용한 것처럼 처리합니다.

참고: 지정한 이미지가 불투명해서 아래의 배경색을 볼 수 없더라도 background-color는 지정해야 합니다. 네트워크가 내려가는 등 이미지를 불러올 수 없더라도 배경 색으로 대체할 수 있기 때문입니다,

구문

각각의 배경 이미지는 none 키워드나 <image> 값으로 지정할 수 있습니다.

여러 개의 배경 이미지를 지정하려면 쉼표로 구분한 값을 지정하세요.

background-image:
  linear-gradient(to bottom, rgba(255,255,0,0.5), rgba(0,0,255,0.5)),
  url('https://mdn.mozillademos.org/files/7693/catfront.png');

<image>
배경으로 사용할 이미지. 여러 개의 배경 이미지를 사용할 땐 쉼표로 구분해서 지정하세요.
none
배경 이미지 없음.

형식 구문

<bg-image>#

where
<bg-image> = none | <image>

where
<image> = <url> | <image()> | <image-set()> | <element()> | <cross-fade()> | <gradient>

where
<image()> = image( <image-tags>? [ <image-src>? , <color>? ]! )
<image-set()> = image-set( <image-set-option># )
<element()> = element( <id-selector> )
<cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? )
<gradient> = <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> | <conic-gradient()>

where
<image-tags> = ltr | rtl
<image-src> = <url> | <string>
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>
<image-set-option> = [ <image> | <string> ] <resolution>
<id-selector> = <hash-token>
<cf-mixing-image> = <percentage>? && <image>
<cf-final-image> = <image> | <color>
<linear-gradient()> = linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
<repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
<conic-gradient()> = conic-gradient( [ from <angle> ]? [ at <position> ]?, <angular-color-stop-list> )

where
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
<hsl()> = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )
<hsla()> = hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )
<side-or-corner> = [ left | right ] || [ top | bottom ]
<color-stop-list> = [ <linear-color-stop> [, <linear-color-hint>]? ]# , <linear-color-stop>
<ending-shape> = circle | ellipse
<size> = closest-side | farthest-side | closest-corner | farthest-corner | <length> | <length-percentage>{2}
<position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]
<angular-color-stop-list> = [ <angular-color-stop> [, <angular-color-hint>]? ]# , <angular-color-stop>

where
<alpha-value> = <number> | <percentage>
<hue> = <number> | <angle>
<linear-color-stop> = <color> && <color-stop-length>
<linear-color-hint> = <length-percentage>
<length-percentage> = <length> | <percentage>
<angular-color-stop> = <color> && <color-stop-angle>?
<angular-color-hint> = <angle-percentage>

where
<color-stop-length> = <length-percentage>{1,2}
<color-stop-angle> = <angle-percentage>{1,2}
<angle-percentage> = <angle> | <percentage>

예제

별 모양 이미지는 배경이 투명하고, 고양이 이미지 위에 위치합니다.

HTML

<div>
  <p class="catsandstars">
    This paragraph is full of cats<br />and stars.
  </p>
  <p>This paragraph is not.</p>
  <p class="catsandstars">
    Here are more cats for you.<br />Look at them!
  </p>
  <p>And no more.</p>
</div>

CSS

p {
  font-size: 1.5em;
  color: #FE7F88;
  background-image: none;
  background-color: transparent;
}

div {
  background-image:
      url("https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png");
}

.catsandstars {
  background-image:
      url("https://mdn.mozillademos.org/files/11991/startransparent.gif"), 
      url("https://mdn.mozillademos.org/files/7693/catfront.png");
  background-color: transparent;
}

결과

접근성 고려사항

보조 기술은 배경 이미지를 읽을 수 없습니다. 이미지가 페이지 목적의 이해에 필수적인 정보를 갖고 있다면 문서에서 구조적으로 설명하는 편이 좋습니다.

명세

명세 상태 주석
CSS Backgrounds and Borders Module Level 3
The definition of 'background-image' in that specification.
Candidate Recommendation From CSS2 Revision 1, the property has been extended to support multiple backgrounds and any <image> CSS data type.
CSS Level 2 (Revision 1)
The definition of 'background-image' in that specification.
Recommendation From CSS1, the way images with and without intrinsic dimensions are handled is now described.
CSS Level 1
The definition of 'background-image' in that specification.
Recommendation  

초기값none
적용대상all elements. It also applies to ::first-letter and ::first-line.
상속no
Mediavisual
Computed valueas specified, but with <url> values made absolute
Animation typediscrete
Canonical orderthe unique non-ambiguous order defined by the formal grammar

브라우저 호환성

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
background-imageChrome Full support 1Edge Full support 12Firefox Full support 1
Notes
Full support 1
Notes
Notes If the browser.display.use_document_colors user preference in about:config is set to false, background images will not be displayed.
IE Full support 4Opera Full support 3.5Safari Full support 1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4
Notes
Full support 4
Notes
Notes If the browser.display.use_document_colors user preference in about:config is set to false, background images will not be displayed.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
Multiple backgroundsChrome Full support 1Edge Full support 12Firefox Full support 3.6IE Full support 9Opera Full support YesSafari Full support 1.3WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
GradientsChrome Full support 1
Notes
Full support 1
Notes
Notes Some versions support only experimental gradients prefixed with -webkit.
Edge Full support 12Firefox Full support 3.6
Notes
Full support 3.6
Notes
Notes Some versions support only experimental gradients prefixed with -moz.
IE Full support 10Opera Full support 11
Notes
Full support 11
Notes
Notes Some versions support only experimental gradients prefixed with -o.
Safari Full support 4
Notes
Full support 4
Notes
Notes Some versions support only experimental gradients prefixed with -webkit.
WebView Android Full support YesChrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Some versions support only experimental gradients prefixed with -webkit.
Edge Mobile Full support YesFirefox Android Full support 4
Notes
Full support 4
Notes
Notes Some versions support only experimental gradients prefixed with -moz.
Opera Android Full support Yes
Notes
Full support Yes
Notes
Notes Some versions support only experimental gradients prefixed with -o.
Safari iOS Full support Yes
Notes
Full support Yes
Notes
Notes Some versions support only experimental gradients prefixed with -webkit.
Samsung Internet Android Full support Yes
SVG imagesChrome Full support 8Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9.5Safari Full support 5
Notes
Full support 5
Notes
Notes Support of SVG in CSS background is incomplete.
WebView Android No support NoChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support 5
Notes
Full support 5
Notes
Notes Support of SVG in CSS background is incomplete.
Samsung Internet Android Full support Yes
element()
Experimental
Chrome No support NoEdge No support NoFirefox Full support 4
Prefixed
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 4
Prefixed
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
image-rect()
Experimental
Chrome No support NoEdge No support NoFirefox Full support 4
Prefixed
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 4
Prefixed
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
image-set()
Experimental
Chrome Full support 21
Prefixed
Full support 21
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge No support NoFirefox No support No
Notes
No support No
Notes
Notes See bug 1107646.
IE No support NoOpera Full support 15
Prefixed
Full support 15
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari Partial support 6
Prefixed Notes
Partial support 6
Prefixed Notes
Prefixed Implemented with the vendor prefix: -webkit-
Notes Support for url images only and x is the only supported resolution unit. See bug 160934.
WebView Android Full support 4.4
Prefixed
Full support 4.4
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android Full support Yes
Prefixed
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge Mobile No support NoFirefox Android No support No
Notes
No support No
Notes
Notes See bug 1107646.
Opera Android Full support 14
Prefixed
Full support 14
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari iOS Partial support 6
Prefixed Notes
Partial support 6
Prefixed Notes
Prefixed Implemented with the vendor prefix: -webkit-
Notes Support for url images only and x is the only supported resolution unit. See bug 160934.
Samsung Internet Android Full support 4.0
Prefixed
Full support 4.0
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-

Legend

Full support  
Full support
Partial support  
Partial support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

같이 보기

문서 태그 및 공헌자

최종 변경자: alattalatta,