HTML Background Image Code
This page contains the HTML code for setting a background image on your webpage. This background image code can be used on any HTML element - you choose! For example, you can set a background image for a table cell, or a div
tag or the body
tag (for the whole page).
This code sets a background image:
This results in:
This box has a background image.
Fixed Background Image
You can use the background-attachment
property to fix the position of a background image so that its position is fixed (even if it's containing block scrolls):
This results in:
This example shows how a background image can be set to a fixed position
- even though its containing block scrolls.
The contents of this box forces scroll bars to appear. When you scroll, you'll notice the image remains fixed.
Shorthand Background Code
You can use the CSS background
property to set all background properties of an HTML element at once:
This results in:
This box has had its all it's background properties set using the 'background' property. The background property is shorthand for setting many properties at once.