HTML Background Code

Here you can get the HTML background code for setting the background of your web page. For example, you an set the background color or specify a background image.

To set the HTML background, you actually use Cascading Style Sheets (CSS). You can set background properties on any HTML element, plus you can do things like, specify an image's position, whether it should repeat, how it should repeat etc.

Background Color

The background-color property allows you to set the background color for any HTML element:

This results in:

This box has had it's background set to the color blue.

Background Image

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

There's a quick way of setting all background properties of an HTML object. You can use the CSS background property to set all the background properties 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.

Enjoy this site?

Thanks for supporting!

© Copyright 2006 - 2017 | Privacy Policy