Never crop the image unless a single image is too large to fit. By doing so, you can scale the image upward or downward as desired. The following example sets the background image of the div element. Put the background image into the HTML folder. [ at ]? This prevents the image repeating across the element (in the event that the image is smaller than the element). If you'd like to contribute to the data, please check out. The background-position property in CSS allows you to move a background image (or gradient) around within its container.. html { background-position: 100px 5px; } It has three different types of values: Length values (e.g. In HTML, background images are set using CSS. Here we scale a 32x32 pixel favicon to 300x300 pixels: As you can see, the CSS is actually essentially identical, save the name of the image file. If multiple images can fit with leftover space, squish them or stretch them to fill the space. Resizing background images with background-size. 100% 5%) Keywords (e.g. In HTML, background images are set using CSS. [ ? Here, we apply a background image to a

element. | hsla( , , , ? Get the latest and greatest from MDN delivered straight to your inbox. We want (for some reason likely involving horrifyingly bad site design) to tile four copies of this image into a 300x300-pixel element.

The contain value specifies that, regardless of the size of the containing box, the background image should be scaled so that each side is as large as possible while not exceeding the length of the corresponding side of the container. The HTML markup will be the same as the previous solution. | rgb( #{3} , ? https://github.com/mdn/interactive-examples, MDN Understanding WCAG, Guideline 1.1 explanations, Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0, CSS Backgrounds and Borders Module Level 3, https://github.com/mdn/browser-compat-data, Resizing background images with background-size, From CSS2 Revision 1, the property has been extended to support multiple backgrounds and any. Here are more background codes and usage examples. Content is available under these licenses. By doing so, you can scale the image upward or downward as desired. ) = cross-fade( , ? Tiling a large image. This article provides HTML background image code - code for setting a background image on an HTML element.

, ) = conic-gradient( [ from ]? Even better, you can use the CSS background property to set all the background properties at once. The first layer specified is drawn as if it is closest to the user. Let's take a look at these. , ) = radial-gradient( [ || ]? ]! , ? The source for this interactive example is stored in a GitHub repository. | rgba( #{3} , ? ) The background images are drawn on stacking context layers on top of each other.

If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document. Content is available under these licenses. If you want the background image to appear on a single page only, surround the code by