CSS Background

In CSS, the background property is used to set the background style of an HTML element. The background property is a shorthand property that allows you to set multiple background-related properties at once, including:

  • background-color: The color of the background.
  • background-image: The URL of the background image.
  • background-repeat: How the background image should be repeated.
  • background-position: The starting position of the background image.
  • background-size: The size of the background image.
  • background-attachment: Whether the background image should scroll with the content or remain fixed.

Here's an example of how to use the background shorthand property to set the background color and image for an HTML element:

div {
    background: #fff url('background.jpg') no-repeat top right;
  }

In this example, we're setting the background property to a white background color (#fff), the URL of an image file (background.jpg), and the position of the background image (no-repeat top right).

Here are some of the possible values for the background shorthand property:

  /* Set background color */
    background: #ffffff;
    
    /* Set background image */
    background: url('image.jpg');
    
    /* Set background image with repeat */
    background: url('image.jpg') repeat;
    
    /* Set background image with no repeat */
    background: url('image.jpg') no-repeat;
    
    /* Set background image with repeat x and repeat y */
    background: url('image.jpg') repeat-x repeat-y;
    
    /* Set background image position */
    background: url('image.jpg') 10px 20px;
    
    /* Set background image size */
    background: url('image.jpg') / 50% 50%;
    
    /* Set background attachment */
    background: fixed;

You can also use each of the individual background properties separately to achieve more control over the background style of your HTML elements.