Starting a New Site & CSS Background Images
Master CSS background images for stunning web designs
Core CSS Background Properties
background-image
Sets the image source using url() function. Forms the foundation of visual backgrounds.
background-position
Controls horizontal and vertical placement using keywords, pixels, or percentages.
background-size
Defines scaling behavior with values like cover, contain, or specific dimensions.
This tutorial builds a coffee subscription site's hero section, providing hands-on experience with CSS background images in a real-world context.
Project Setup Process
Open Project Folder
Navigate to Desktop > Class Files > Web Dev Class > Hipstirred Hero and open the entire folder in your code editor
Configure Page Title
Edit the title tag to 'Artisanal Coffee Curators—Hipstirred' for proper page identification
Set Up Live Preview
Open index.html in Chrome and keep it open for real-time development feedback
Using a div element for the hero section is appropriate since there's no specific semantic tag for this type of promotional content overlay.
Default vs Custom Styling
| Feature | Browser Default | Custom Styling |
|---|---|---|
| Body Margin | 8px | 0px |
| Font Family | Times/serif | sans-serif |
| Heading Size | ~32px | 95px |
Keep the background-color even when adding background-image. The color displays while the image loads, ensuring white text remains readable.
Background Position Values
Keywords
Use top, bottom, left, right, center for common positioning needs.
Pixels
Absolute positioning with specific pixel offsets from top-left corner.
Percentages
Relative positioning that adapts to container size changes dynamically.
Fixed vs Responsive Padding
| Feature | 30px Fixed | 10% Responsive |
|---|---|---|
| 320px Mobile | 30px (9.4%) | 32px (10%) |
| 768px Tablet | 30px (3.9%) | 77px (10%) |
| 1440px Desktop | 30px (2.1%) | 144px (10%) |
Background Repeat Options
repeat (default)
Image tiles in both directions to fill the entire container space.
no-repeat
Image appears once only, ideal for hero photos and single graphics.
repeat-x / repeat-y
Creates horizontal rows or vertical columns of repeated images.
Background-Size: Cover vs Contain
Use Shift + Arrow keys in DevTools to increment percentage values by 10% for quick background-position adjustments.
Background Position Reference
Key Takeaways





