w1coding.comAll tutorials

CSS Background

CSS lessons
  1. Environment Setup
  2. Introduction
  3. Tdisplay
  4. Basics
  5. Editors
  6. Syntax
  7. Colors
  8. Background
  9. Borders
  10. Margins
  11. Padding
  12. Width And Height
  13. Outline
  14. Texts
  15. Fonts
  16. Icons
  17. Links
  18. Lists
  19. Display
  20. Tables
  21. Max And With
  22. Positon
  23. Z Index
  24. Dropdown
  25. Overflow
  26. Float
  27. Navigation
  28. Image Sprites

CSS Background Properties

Background Color

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

Example of Background Color: #3498db

Background Image

The background-image property sets an image as the background of an element.

Example of Background Image

Background Repeat

The background-repeat property controls whether a background image repeats. It can be set to repeat, no-repeat, repeat-x, or repeat-y.

Example of Repeated Background Image

Background Position

The background-position property specifies the starting position of a background image. Common values include center, top, bottom, left, and right.

Example of Centered Background Image

Background Size

The background-size property sets the size of the background image. Values include cover, contain, or specific dimensions like 100px 100px.

Example of Contained Background Image

Background Attachment

The background-attachment property sets whether a background image scrolls with the page (scroll) or stays fixed (fixed).

Example of Fixed Background Image

Combining Background Properties

You can combine multiple background properties in one shorthand property. For example:

background: url('image.jpg') no-repeat center/cover fixed;

This shorthand combines background-image, background-repeat, background-position, background-size, and background-attachment.