With CSS you can make an image the background not only of the entire body of pages, but also of individual elements too. All you need to do is use the background property and provide the path to the image.
Let’s say you have this boring page, and you want to punch it up by using a fun image as the background:
Here’s the CSS you would use to add a fun background:
- body{
- background: url(path/to/image.jpg);
- background-size: cover;
- }
Make sure to put the path to your image — either a locally hosted image or a live URL to an image you’ve found online (although saving the background to your server and linking to a local image is definitely the best way to go) in the url parameters for the background property. In this particular case we also used the background-size property to make sure that the image was appropriately sized to the browser). Other properties you can use to customize the way your background image appears on your site are background-position, background-repeat, and background-attachment. Keep in mind that this same CSS technique can be used to set images as backgrounds for elements other than the body, such as divs. Here are the results (results will vary based on which image you choose to use!):