CSS Tutorials

Overview

The CSS background properties are used to add backgrounds and background effects to the HTML page and HTML elements.

Note

The following are basic examples. Towards the bottom of this page you’ll find a complete list of all applicable properties, where you can find more information on the properties discussed, and sometimes find more involved properties not discussed on this page.

Background Color

The background-color property sets the background color of the entirety of an element.

div {
    background-color: red;
}

Background Image

The background-image property sets one or more background images (with varying placement) for an element. The default placement is at the top-left corner.

div {
    background-image: url("my-background.jpg");
}

Setting the Image Size, Repeat, and Position

The background-size property specifies the size of the background image. By default an image that doesn’t fill the element will repeat both vertically and horizontally starting from the top, left position. This can be changed.

div {
    background-image: url("my-background.jpg");
    background-size: 400px 200px;
    background-repeat: no-repeat;
    background-positon: right center;
}

Background Gradient

CSS lets you create smooth gradients between two or more specified colors.

Linear Gradient

div {
    height: 100px;
    background-color: red; /* default for browsers that don't support gradients */
    background-image: linear-gradient(to right, red , blue);
}

Radial Gradient

div {
    height: 100px;
    background-color: red; /* default for browsers that don't support gradients */
    background-image: radial-gradient(red, blue, green);
}

Conic Gradient

div {
    height: 100px;
    background-color: red; /* default for browsers that don't support gradients */
    background-image: conic-gradient(red, yellow, blue, green);
}

Background Properties

  • CSS – background Property
    The background property is a shorthand property for all the other properties a CSS background can be given.
  • CSS – background-attachment Property
    The background-attachment property determines whether the background image scrolls with the rest of the page or is fixed in place as the page scrolls.
  • CSS – background-blend-mode Property
    The background-blend-mode property defines the blending mode of each background color and/or image layer.
  • CSS – background-clip Property
    The background-clip property defines how far the background color or image should extend within an element.
  • CSS – background-color Property
    The background-color property sets the background color of the entirety of an element including padding and border, but not margin.
  • CSS – background-image Property
    The background-image property sets one or more background images (with varying placement) for an element. The default placement is at the top-left corner.
  • CSS – background-origin Property
    The background-origin property specifies the positioning area of a background image (this property has no effect if the background-attachment is fixed).
  • CSS – background-position Property
    The background-position property sets the starting position of a background image, which by default is the top-left corner of an element. Unless otherwise specified, the image will repeat both vertically and horizontally to fill the element.
  • CSS – background-repeat Property
    The background-repeat property sets how a background image will be repeated if at all. By default, the background image is repeated both vertically and horizontally.
  • CSS – background-size Property
    The background-size property specifies the size of the background image.

CSS Notes:


We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.