FREE HTML CODE
Search HTML Code

HTML Background Image Code

Background Image Example

The following example specifies a background image for the whole page (via the 'body' tag). We position the image in the center of the page and prevent it from repeating across the page.



body {
  background-image: url("http://yoursite.com/images/image_name.gif");
  background-position: 50% 50%;
  background-repeat: no-repeat;
}

Even better, you can use the CSS background property to set all the background properties at once. Therefore, we could rewrite the above code to this:


body {
  background: url("http://yoursite.com/images/image_name.gif") 50% 50% no-repeat;
}


Where Do I Put the Code?

To apply the background image to every page on your website, put the code into an external style sheet.

If you want the background image to appear on a single page only, surround the code by <style> tags, and place between the document's <head> tags.
| More