CodeLab
Tutorials For Everyone
Run
<!Doctype HTML> <html> <head> <title>Background Size</title> <style> .size1 { border: 20px dotted black; padding: 20px; background: url("https://www.tutsinsider.com/wp-content/uploads/2019/08/taj-mahal.jpg"); background-size: cover; background-repeat: no-repeat; background-origin: border-box; margin: 30px; } .size2 { border: 20px dotted black; padding: 20px; background: url("https://www.tutsinsider.com/wp-content/uploads/2019/08/taj-mahal.jpg"); background-size: 300px 50px; background-repeat: no-repeat; background-origin: border-box; margin: 30px; } .size3 { border: 20px dotted black; padding: 20px; background: url("https://www.tutsinsider.com/wp-content/uploads/2019/08/taj-mahal.jpg"); background-size: contain; background-repeat: no-repeat; background-origin: border-box; margin: 30px; } .size4 { border: 20px dotted black; padding: 20px; background: url("https://www.tutsinsider.com/wp-content/uploads/2019/08/taj-mahal.jpg"); background-size: 90% 30%; background-repeat: no-repeat; background-origin: border-box; margin: 30px; } .size5 { border: 20px dotted black; padding: 20px; background: url("https://www.tutsinsider.com/wp-content/uploads/2019/08/taj-mahal.jpg"); background-size: auto; background-repeat: no-repeat; background-origin: border-box; margin: 30px; } </style> </head> <body> <h2>Background Size Property</h2> Background size property defines the size of background image. See following examples. <div class="size1"> cover: defines the background image size to cover the whole block by resizing. </div> <div class="size2"> length: defines the background image size in values. </div> <div class="size3"> contain: defines the background image size to make it fully visible by resizing. </div> <div class="size4"> percentage: defines the background image size in percentages. </div> <div class="size5"> auto: defines the background image size to default size. </div> </body> </html>