in CSS

Create A Full Page Background Image

In this snippet we are looking at what you can do with the CSS background-size property. This property will allow you to define the size of the image that you have defined as the background image, similar to how you will use the width and height when adding an image. The value of the background-size property can either be:

  • Contain - This specifies that the image should be scaled to as large as possible while being less or equal to the background of the element.
  • Cover - This specifies that the image should be scaled to as small as possible while being greater or equal to the background of the element.
  • Percentage
  • Length
  • Auto

    Therefore to make the image cover the entire background of the HTML element you will need to use the cover value just like the snippet below.

html {
  background: url(img/background.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email