Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

CSS Background Code

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.

CodeResult

This text has a background color applied.

CSS Background Image

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

CodeResult

This text has a background image applied.

CSS Background Repeat

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

CodeResult

This background image does not repeat.

CSS Background Position

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

CodeResult

This background image is positioned 100 pixels in from the left.

CSS Background Attachment

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

CodeResult

This background image is fixed - it doesn't scroll with its outer container. This example uses the CSS overflow property to force the box to scroll when there's too much text to fit in the box.

Shorthand Code

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

CodeResult

This paragraph tag has been styled using the 'background' property, which is shorthand for setting multiple properties for an HTML element.

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!