- background-image
- Try it
- Syntax
- Values
- Accessibility concerns
- Formal definition
- Formal syntax
- Examples
- Layering background images
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- How to Set GIF as a Background Image on the Webpage?
- How to Set GIF as a Background Image on the Webpage?
- Conclusion
- About the author
- Abdul Moeed
- Можно ли сделать анимированный фон?
- CSS background-image Property
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Example
- Example
- Example
- Example
- Example
- Example
- Example
background-image
The background-image CSS property sets one or more background images on an element.
Try it
The background images are drawn on stacking context layers on top of each other. The first layer specified is drawn as if it is closest to the user.
The borders of the element are then drawn on top of them, and the background-color is drawn beneath them. How the images are drawn relative to the box and its borders is defined by the background-clip and background-origin CSS properties.
If a specified image cannot be drawn (for example, when the file denoted by the specified URI cannot be loaded), browsers handle it as they would a none value.
Note: Even if the images are opaque and the color won’t be displayed in normal circumstances, web developers should always specify a background-color . If the images cannot be loaded—for instance, when the network is down—the background color will be used as a fallback.
Syntax
Each background image is specified either as the keyword none or as an value.
To specify multiple background images, supply multiple values, separated by a comma:
background-image: linear-gradient( to bottom, rgba(255, 255, 0, 0.5), rgba(0, 0, 255, 0.5) ), url("catfront.png"); /* Global values */ background-image: inherit; background-image: initial; background-image: revert; background-image: revert-layer; background-image: unset;
Values
Is a keyword denoting the absence of images.
Accessibility concerns
Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page’s overall purpose, it is better to describe it semantically in the document.
Formal definition
Initial value | none |
---|---|
Applies to | all elements. It also applies to ::first-letter and ::first-line . |
Inherited | no |
Computed value | as specified, but with url() values made absolute |
Animation type | discrete |
Formal syntax
Examples
Layering background images
Note that the star image is partially transparent and is layered over the cat image.
HTML
div> p class="catsandstars">This paragraph is full of catsbr />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("mdn_logo_only_color.png"); > .catsandstars background-image: url("startransparent.gif"), url("catfront.png"); background-color: transparent; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
- Implementing image sprites in CSS
- Image-related data types: ,
- Image-related functions:
- cross-fade()
- element()
- image()
- image-set()
- linear-gradient()
- radial-gradient()
- conic-gradient()
- repeating-linear-gradient()
- repeating-radial-gradient()
- repeating-conic-gradient()
- paint()
- url()
Found a content problem with this page?
This page was last modified on Jul 18, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.How to Set GIF as a Background Image on the Webpage?
Setting the GIF “Graphics Interchange Format” as a background image adds a visually appealing element to the design. GIF allows developers to convey information or highlight a product or service which helps in creating a brand’s visual identity. However, the developers must ensure that the usage of GIFs does not overwhelm the webpage or distract the user from the main content.
This article demonstrates the procedure of setting a GIF as a background image on the webpage.
How to Set GIF as a Background Image on the Webpage?
Setting a GIF as a background image helps in creating eye-catching elements by adding visual elements.
GIFs are particularly useful on websites that want to convey a sense of playfulness or whimsy, or on pages that want to highlight a particular product or feature. For setting it, as a background image visit the following examples:
Example 1: Setting GIF as a Fixed Background
As the HTML elements that help in building the content of the webpage are placed inside the “ ” tag. That is why, selecting the “body” element and applying CSS properties on it. It affects all the containing HTML elements of the “ ” tag.
For instance, the “ ” and “ ” tags are utilized as the content of the webpage. See the below code snippet:
< body >
< h1 >Setting GIF as a Background Image On The Page
< p >This GIF has been added as a background image on the whole page using «background-image» Property. This Article has been powered by Linuxhint.