MODULE 03 · CSS FOUNDATIONS

Colors, Backgrounds & Borders

Selectors decide what gets styled — now it's time to actually make things look good. Color formats, background properties, and border styling that turn a plain box into a designed one.

Day 17 of 30 Beginner ~18 min

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.

Three Ways to Write a Color

CSS accepts several notations for color. They're interchangeable — pick whichever is clearest for the situation.

FORMAT EXAMPLE & NOTES
Named

color: tomato; — readable, but only ~140 names exist and they're imprecise.

Hex

color: #e8590c; — six-digit hex code, the most common format in real projects.

RGB

color: rgb(232, 89, 12); — same color as red, green, blue values from 0–255.

RGBA

color: rgba(232, 89, 12, 0.5); — adds an alpha channel for transparency.

SAME COLOR, THREE FORMATS
tomato
#e8590c
rgb(30,111,167)
rgba(…,0.55)

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.

style.css
.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);
}
SHORTHAND

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.

style.css
/* 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;
}
BORDER STYLES SIDE BY SIDE
solid
dashed
dotted
border-radius

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.

LOW VS HIGH CONTRAST
HARD TO READ Light gray text on a white background strains the eyes and fails accessibility guidelines.
EASY TO READ Dark ink text on a light background gives strong, comfortable contrast for everyone.

Breaking Down What You Just Learned

1

Color formatsNamed, hex, rgb(), and rgba() all describe color — rgba() adds transparency.

2

Background propertiesbackground-color, background-image, and background-size control what fills an element.

3

Gradientslinear-gradient() creates smooth color transitions without an image file.

4

Border shorthandborder needs width, style, and color together to render visibly.

5

ContrastText and background colors need enough contrast to stay readable.

Try It Yourself

EXERCISE

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

HANDS-ON EXERCISE

Practicing color, background, and border together

Create day17.html linked to a stylesheet and build three simple "card" divs.

  1. Build three <div class="card"> elements, each with a heading and a short paragraph.
  2. Give card one a solid background-color and a solid border in a different color.
  3. Give card two a linear-gradient background and a dashed border with border-radius.
  4. Give card three a background-image with background-size: cover and a dotted border.
  5. Check text contrast on each card and adjust colors until every card is easy to read.

Recap

COLOR FORMATS

Named, hex, rgb(), and rgba() — all interchangeable ways to describe a color.

BACKGROUNDS

Solid colors, images, and gradients all fill the space behind an element.

BORDERS

Width, style, and color combine to draw a visible border.

CONTRAST

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.
Course Overview