Here are the background properties:
| Description | Property |
|---|---|
| Background Color | background-color |
| Background Image | background-image |
| Background Repeat | background-repeat |
| Background Position | background-position |
| Background Size | background-size |
| Background Attachment | background-attachment |
| Background Shorthand | background |
Background Image
Use background images in web pages for decorative visual effects.
| |
Background Image Repeat
background-repeat has four values:
| Effect | No Repeat | Repeat (Default) | Horizontal Repeat | Vertical Repeat |
|---|---|---|---|---|
| Value | no-repeat | repeat | repeat-x | repeat-y |
Background Position
background-position takes values like horizontal position vertical position. Positions can be keywords or coordinates.
Keywords include left, right, center, top, bottom.
Coordinates use number + px, and can be positive or negative.
| |
You can specify just one keyword; the other direction will default to center. If you use a single number, it applies to the horizontal direction, with vertical centered.
Background Size
background-size commonly uses three types of values:
- Keywords
cover: Scales the background image proportionally to completely cover the background area. Parts of the image might be clipped.contain: Scales the background image proportionally to fit entirely within the background area. Parts of the background might be empty.
- Percentage: Calculates image size based on the box dimensions.
- Number + unit (e.g., px).
When using 100% for percentage, the image width matches the box width, and height scales proportionally.
Background Attachment
background-attachment prevents the background from scrolling with the element’s content. The value is fixed.
Background Shorthand Property
The background property value is background-color background-image background-repeat background-position/background-size background-attachment. Order doesn’t matter.
| |