make background image fit div code example

Example 1: how to set a full size background image in html

<head>
<style>
#example1{
  border: 2px solid black;
  padding: 100px;
  background: url(mountain.jpg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
</style>
</head>
<body>
<div id="example1">
</div>
</body>

Example 2: background image fill div

div {
	background-image: url("example.com/image.png");
    background-repeat: no-repeat;
    background-size: cover;
}

Example 3: make image stretch to fit div

Just apply without any changing any code
img {
width: 100%;
}

Tags:

Html Example