CSS Background Image Codes

Below are some sample CSS background image codes for displaying a fixed background image on a website.

If you want an image to scroll with your web page use the code below. Replace filename.jpg with your image name and make sure you put the correct path to the image as well.

body {
background-image: url(filename.jpg);
background-attachment: scroll;
background-repeat: no-repeat;
}

You can also make the background image to be fixed, so when you scroll the webpage up and down, the background image stays static and doesn’t move. Replace filename.jpg with your image name and make sure you put the correct path to the image as well.

body {
background-image: url(filename.jpg);
background-attachment: fixed;
background-repeat: no-repeat;
}

If you are using a single image for the background make sure it’s large enough to cover you web page. You can also use a small image and repeat it horizontally or vertically.

This entry was posted in Tips and Tricks and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>