JT Book a call

Blog

How to use background-size in CSS

Published

1 min read

How to use background-size in CSS
In this post

The CSS background-size property sets the size of the background image of the element. Images can be left to full size, stretched or limited to fit the available space.

background-image: url('some-example-image.jpg');

Cover #

background-size: cover;

Image description

Size in pixels or percentage #

background-size: 300px;

Image description

background-size: 15%;

Image description

Contain #

background-size: contain;

Image description

Background-Repeat #

If the container is larger than the image, this will mosaic the image if the background-repeat property is not set to no-repeat.

background-repeat: no-repeat;

Image description

Background-Position #

The background-position CSS property sets the initial position for each background image.

background-position: center;

Image description

Background-Color #

Spaces not covered by the background image are filled with the background-color property, and the background color will be visible on background images that have transparency.

background-color: lightgreen;

Image description

Read next

Tell us whatyou need built

JetThoughts has been building software since 2008. Book a call, or write to sales@jetthoughts.com. You'll leave the call with a written one-page scope within 2 working days.

#01 Paul Keen
Paul KeenFounder

A 30-minute call; pick a time.