This page contains HTML background image code. Using this code, you can add a background image to any HTML element.
You can add a background image to any HTML element by using the CSS
background-image property. You can also use the
background property, which allows/requires you to add other background related properties at the same time.
Here are some examples of adding a background image to an HTML document.
background-image property allows you to add a background image to an HTML element. In the following example, we have a background image appearing behind the text.
Note that when using the
background-image property, you should also specify a background color by using the
background-color property. The background color is used in the event that the background image can't be displayed.
In case your background image is smaller than the HTML element that contains it, you have the option of letting your background image repeat/tile across the page/element, or just display once.
You can specify this using the
background-repeat property. If you don't use this property, most browsers will repeat your image by default. If you don't want this to happen, just specify
You can also specify
repeat-x to repeat horizontally only, or
repeat-y to repeat vertically only.
You can determine the position that your background image appears within its containing box. For example, you might want your image to appear in the center. Or you might want it to appear at the top, right. In any case, you can specify your background image's position by using the
Example - With
Example - With
In this example, the background image repeats horizontally across the
You can "fix" your background image in the same place so that, even when the user scrolls, it remains fixed. In other words, the background image doesn't scroll (even though the rest of the content scrolls).
Here's an example:
As mentioned, the CSS
background property allows you to add all your background related properties all in one go.
This is a more efficient way to code your background image properties.
Here's an example of using the