Why This Trio Matters
Color, background, and border properties are the fastest way to make raw HTML look intentional. They're also where most beginners start experimenting — small changes here have an immediate, visible effect, which makes them a great way to build intuition for how CSS works.
- ✓CSS supports several color formats — named colors, hex, and rgb() — each with its own tradeoffs.
- ✓Backgrounds aren't just solid fills; they can hold images, gradients, and positioning rules.
- ✓Borders are defined by three parts together: width, style, and color.
Three Ways to Write a Color
CSS accepts several notations for color. They're interchangeable — pick whichever is clearest for the situation.
color: tomato; — readable, but only ~140 names exist and they're imprecise.
color: #e8590c; — six-digit hex code, the most common format in real projects.
color: rgb(232, 89, 12); — same color as red, green, blue values from 0–255.
color: rgba(232, 89, 12, 0.5); — adds an alpha channel for transparency.
Filling and Framing an Element
The background group of properties controls what fills the space behind an element's content — a flat color, an image, or a gradient.
.card { background-color: #fff1e6; background-image: url("texture.png"); background-repeat: no-repeat; background-position: center; background-size: cover; } /* A gradient background, no image file needed */ .banner { background: linear-gradient(135deg, #e8590c, #c2447a); }
background: #fff1e6 url("texture.png") no-repeat center / cover; sets color, image, repeat, position, and size in one line — but only once you're comfortable with each piece individually.
Width, Style & Color Together
A border needs all three parts to render: a width, a style (solid, dashed, dotted...), and a color. border-radius rounds the corners after the border is set.
/* Longhand: three properties */ .box { border-width: 3px; border-style: solid; border-color: #e8590c; } /* Shorthand: same result, one line */ .box { border: 3px solid #e8590c; border-radius: 14px; }
Color Choices Affect Readability
A background and text color that are too close in brightness make content hard to read, regardless of how nice the colors look individually.
Breaking Down What You Just Learned
Color formatsNamed, hex, rgb(), and rgba() all describe color — rgba() adds transparency.
Background propertiesbackground-color, background-image, and background-size control what fills an element.
Gradientslinear-gradient() creates smooth color transitions without an image file.
Border shorthandborder needs width, style, and color together to render visibly.
ContrastText and background colors need enough contrast to stay readable.
Try It Yourself
Take one element from yesterday's page and give it a background color, a 3px solid border in a contrasting color, and a border-radius of your choice. Then swap the background for a two-color linear-gradient.
Build a Set of Styled Cards
Practicing color, background, and border together
Create day17.html linked to a stylesheet and build three simple "card" divs.
- Build three <div class="card"> elements, each with a heading and a short paragraph.
- Give card one a solid background-color and a solid border in a different color.
- Give card two a linear-gradient background and a dashed border with border-radius.
- Give card three a background-image with background-size: cover and a dotted border.
- Check text contrast on each card and adjust colors until every card is easy to read.
Recap
Named, hex, rgb(), and rgba() — all interchangeable ways to describe a color.
Solid colors, images, and gradients all fill the space behind an element.
Width, style, and color combine to draw a visible border.
Enough brightness difference between text and background keeps content readable.
Key Takeaways
- Hex and rgb() are the most common ways to specify color in real projects.
- rgba() adds a fourth value for transparency, useful for overlays and subtle tints.
- background-image, background-size, and background-position work together to place an image.
- linear-gradient() creates smooth color transitions without needing an image file.
- A border needs width, style, and color together — and border-radius rounds its corners.