CSS Background Code

You can use CSS to add background effects to any HTML element.

The following CSS background codes demonstrate the various CSS properties you can use to style the background of any HTML element.

CSS Background Color

To set the background color of an element, use the background-color property.

CSS Background Image

To add a background image to an element, use the background-image property.

CSS Background Repeat

Determines whether the background image repeats (tiles) or not. For info on the possible values, see background-repeat.

CSS Background Position

Determines the position of the background image. For more information, see background-position.

CSS Background Attachment

Determines whether or not the background image scrolls with the outer container. For more information, see background-attachment.

Shorthand Code

You can use the background property to set all the background properties at once. For more information, see background.