How To Add Background Image In CSS?

Use the `background-image` property

Example: `background-image: url(“image.jpg”);`

Apply it to the desired selector, such as `body`, `div`, or `.class`

Example: `body { background-image: url(“background.jpg”); }`

Use `background-repeat: no-repeat;` to prevent tiling

Use `background-size: cover;` to make the image fill the element

Use `background-position: center;` to center the image

Use `background-attachment: fixed;` to keep the image fixed while scrolling

Use the shorthand `background` property if needed

Example: `background: url(“image.jpg”) no-repeat center center / cover;`

Suggested for You

Trending Today