How to add a background image in HTML?

To add a background image in HTML, you can use CSS to apply the background image to an HTML element. Basic syntax :

body {
/* Specify the background image URL */
background-image: url('background-image.jpg');
/* Set background image size to cover entire viewport */
background-size: cover;
/* Center the background image */
background-position: center;
/* Fix the background image so it doesn't scroll with content */
background-attachment: fixed;
}

Go from files to website in seconds.

Start a free trial for 7 days — no credit card required

Get Started for Free