Images.

And also, the image dimension is excessive on small-screen devices (more on this further down in this tutorial).However, this technique will also work on any block-level element (such as a The most essential property/value pair to pay attention to is:That’s where the magic happens. Use the BackgroundImageLayout property to specify the position and behavior of an image you have placed onto a control.

The background-size CSS property lets you resize the background image of an element, overriding the default behavior of tiling the image at its full size by specifying the width and/or height of the image. We want (for some reason likely involving horrifyingly bad site design) to tile four copies of this image into a 300x300-pixel element.

This property/value pair tells the browser to scale the background image proportionally so that its width and height are equal to, or greater than, the width/height of the element. Jennifer Kyrnin is a professional web developer who assists others in learning web design, HTML, CSS, and XML. Here's what the image looks like at its original size: The above example uses the background-size property to stretch the background image to 100% of the width, and 110% of the height, of its container.
Background image Bootstrap background image.

Lifewire uses cookies to provide you with a great user experience. In this tutorial, we’ll go over the simplest technique for making a background image fully stretch out to cover the entire browser viewport. That Drives Results®

The length value can be in form of px, em, % etc. Bill has over 25 years of experience in the Internet marketing industry specializing in SEO, UX, information architecture, marketing automation and more. This way, the background image will cover the entire element, with no stretching (the image will For example, you can have the background image stretch (and contract) to whatever size the element is that it is applied against.

can set the Try resizing the browser window, and you will see that the image will stretch, but always cover the entire element.From the examples above you have learned that background images can be styled by using the CSS background properties.To learn more about CSS background properties, study our If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: Doing this reduced the file size down from 1741KB to 114KB. This is especially true for responsive websites that are

Windows 10 is quite an impressive operating system. When the output area and the image have different aspect ratios, the image is distorted by this stretching. By using Lifewire, you accept ourTips for Creating a Background Watermark on a Web PageHow to Add Responsive Background Images to a WebsiteHow to Use CSS to Center Images and Other HTML ObjectsHow to Add a Fixed Background Image to Emails in Outlook This dimension will have us covered on most widescreen computer monitors currently being sold in the market, but at the expense of serving up a 1.7MB file.That huge of a payload just for a background photo is never a good thing under any sort of situation, but it’s exceptionally bad on mobile internet connections. specify the background image on the If the background image is smaller than the element, the image will repeat itself, The best way to stretch an image to fit the background of an element is to use the

This is also the reason why you should set a good default background color so the user can read the content while the background image is loading.Optimizing your Web images before putting them up on production is never a bad idea either; we’ve got some articles to help with this:No need to ask permission if you want to use the source code included in this tutorial; I’ve placed the tutorial’s code in the public domain under Join our mission to provide industry-leading digital marketing services to businesses around the globe - all while building your personal knowledge and growing as an individual.Be the first to know when we publish a new blog post!Join 150,000 marketing managers who get our best digital marketing insights, strategies and tips delivered straight to their inbox. In this tutorial, we’ll go over the simplest technique for making a background image fully stretch out to cover the entire browser viewport. Examples of Responsive Full Background Images When an image is scaled up above its natural dimensions, image quality is affected. View Demo. The background-size property also accepts values that prevent the image from stretching out of proportion.. To add a background image on an HTML element, you can use the styleattribute: You can also specify the background image in the