This page shows four boxes with the same background image but different background sizes. Each box demonstrates how the image changes shape and size depending on the background-size property.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Background Size Example</title>
<style>
.box {
width: 20rem;
height: 12rem;
border: 2px solid #333;
margin: 1rem;
background-image: url('https://via.placeholder.com/300x150');
background-repeat: no-repeat;
background-position: center;
display: inline-block;
vertical-align: top;
}
.cover {
background-size: cover;
}
.contain {
background-size: contain;
}
.fixed-size {
background-size: 100px 50px;
}
.auto {
background-size: auto;
}
</style>
</head>
<body>
<h1>Background Size Examples</h1>
<section>
<article class="box cover" aria-label="Background size cover">
<strong>cover</strong>
</article>
<article class="box contain" aria-label="Background size contain">
<strong>contain</strong>
</article>
<article class="box fixed-size" aria-label="Background size 100px by 50px">
<strong>100px 50px</strong>
</article>
<article class="box auto" aria-label="Background size auto">
<strong>auto</strong>
</article>
</section>
</body>
</html>