Contact Us | +1 888 239-0733 (Toll free US/CA) Mon-Fri: 7:30am to 4:30pm (PST)

CSS 'background-size' Property Explained

Est. Reading: 2 minutes
Updated: April 4, 2024

The CSS 'background-size' property specifies the size of the background images. The size can be set as specific dimensions, scaled to fit the content in various ways, or stretched to cover the element's background area. This property is key for designing responsive backgrounds that adapt to the element's size and ensuring that background images are displayed correctly across different screen sizes and resolutions.

CSS 'background-size' Property Examples

See the Pen CSS 'background-size' Property by Webzstore (@webzstore) on CodePen.

The 'background-size' property is an essential tool for web designers and developers, allowing for versatile background image styling that can adapt to various design needs and enhance the visual appeal of web content.

Browser Support For 'background-size' Property

FirefoxSafariChromeMicrosoft EdgeOpera
4.0
3.6 -moz-
4.1
3.0 -webkit-
4.0
1.0 -webkit-
9.010.5
10.0 -o-

CSS Syntax of the 'background-size' Property

background-size: auto | length | percentage | cover | contain | initial | inherit ;

Usage of the 'background-size' Property

Use 'background-size' to control how a background image should be scaled or stretched within an element. This is particularly useful for creating full-width backgrounds that cover an area without distorting the image's aspect ratio, effectively tiling small images, or fitting an image precisely to a specific design area.

Property Values of the 'background-size' Property

  • Auto: The background image retains its original size.
  • Length: Sets the width and height of the background image using units (e.g., px, em). The first value sets the width, and the second value sets the height. If only one value is given, the second is assumed to be 'auto.'
  • Percentage: This setting sets the size of the background image in percentage values relative to the element's size. The first value is the width, and the second is the height.
  • Cover: Scales the background image to be as large as possible so that the background area is entirely covered by the background image. Some parts of the background image may not be in view within the background positioning area.
  • Contain: Scales the image to fit the largest size so that its width and height can fit inside the content area.
  • Initial: Resets the 'background-size' to its default value (auto).
  • Inherit: Inherits the 'background-size' from the parent element.

Ryan Parker

Ryan has been a standout in digital marketing since 2010. He's the go-to person for getting businesses noticed online, with over 300 projects under his belt—these range from helping local business owners to big online stores. As the Head of Digital Marketing at Webzstore Solutions, Ryan knows all the tricks to make companies shine on the internet. He's excellent at using the latest tech and smart strategies to get results. Ryan is all about making businesses grow and reach more people online.

chevron-down