← Back to the Build Your Homepage series
🚀
EPISODE 02
Selectors, colors, layout — all the way to responsive

Make Your Homepage Beautiful with CSS

Transform the plain homepage from Lesson 1 into something you would actually want to share. Learn selectors, color, the box model, Flexbox, and responsive design — enough CSS to make any site look intentional.

CSSSelectorsFlexboxResponsiveBox Model
Duration
About 3 hours
Level
📊 Beginner (after Lesson 1)
Prerequisite
🎯 Lesson 1 (HTML + GitHub + Vercel)
OUTCOME
A styled, responsive homepage with a real visual hierarchy

What you'll learn

  • 1Connect CSS to HTML using external stylesheets
  • 2Style elements with the right selectors and rules
  • 3Use the box model (padding, margin, border) correctly
  • 4Build flexible layouts with Flexbox
  • 5Adapt the site for phones with media queries

Lesson Flow at a Glance

TimeStepWhat you learn
0:00 – 0:151. What is CSS?How a stylesheet talks to HTML
0:15 – 0:452. Selectors & propertiesHow to target the right thing
0:45 – 1:153. Color and typographyMake text look intentional
1:15 – 1:454. Box modelSpacing without surprises
1:45 – 2:155. Flexbox layoutReal layouts, finally
2:15 – 2:456. Responsive designLooks good on phones too
2:45 – 3:007. Deploy and wrap-upPush and admire

1. What is CSS?

CSS (Cascading Style Sheets) controls how HTML looks. HTML says "this is a heading"; CSS says "this heading is blue, 32px, and centered".

Three ways to apply CSS

MethodExampleWhen
Inline<h1 style="color:blue">Quick demos only
Internal<style>...</style> in <head>Single small page
External<link rel="stylesheet" href="style.css">Real projects (recommended)

We use external CSS — code stays organized and one stylesheet can style many pages.

2. Selectors & Properties

The basic shape

css
selector {
  property: value;
  property: value;
}

h1 {
  color: #2563eb;
  font-size: 32px;
  text-align: center;
}

Common selectors

SelectorTargets
h1, pAll matching tags
.highlightElements with class="highlight"
#heroThe element with id="hero" (only one per page)
a:hoverLinks being hovered
ul > liDirect <li> children of <ul>
💡

Reach for classes by default. IDs are for unique elements; tag selectors are too broad.

3. Color & Typography

Color values

css
h1 { color: red; }              /* keyword */
h2 { color: #ff5733; }          /* hex */
p  { color: rgb(255, 87, 51); } /* rgb */
footer { color: rgba(0, 0, 0, 0.5); } /* with alpha */

Web fonts

Use Google Fonts for quality typography in seconds.

html
<!-- in <head> -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
css
body { font-family: "Inter", system-ui, sans-serif; line-height: 1.6; }

4. The Box Model

Every element is a box made of four layers: content, padding, border, margin.

text
┌─ margin ───────────────────────────────┐
│  ┌─ border ──────────────────────────┐ │
│  │  ┌─ padding ──────────────────┐  │ │
│  │  │       content              │  │ │
│  │  └────────────────────────────┘  │ │
│  └──────────────────────────────────┘ │
└────────────────────────────────────────┘
css
* { box-sizing: border-box; }  /* always start with this */

.card {
  padding: 24px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  margin: 16px 0;
}
⚠️

Without box-sizing: border-box, adding padding makes elements bigger than expected. This one line saves hours.

5. Flexbox

Flexbox makes laying things out a 1-D problem (a row or a column) and solves it elegantly.

css
.navbar {
  display: flex;
  justify-content: space-between;  /* main axis */
  align-items: center;             /* cross axis */
  gap: 16px;
}

.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.card-grid > .card {
  flex: 1 1 280px;   /* grow, shrink, min-width */
}

Key Flexbox properties

PropertyEffect
display: flexTurn the container into a flex container
flex-directionrow (default) or column
justify-contentMain-axis alignment
align-itemsCross-axis alignment
gapSpace between children (no margins needed)

6. Responsive Design

Make a single layout adapt to phones, tablets, and desktops with media queries.

css
/* Mobile first */
.container { padding: 16px; }

@media (min-width: 768px) {
  .container { padding: 32px; max-width: 720px; margin: 0 auto; }
}

@media (min-width: 1024px) {
  .container { max-width: 960px; }
}
💡

Always include <meta name="viewport" content="width=device-width, initial-scale=1"> in your HTML head, or media queries do not work on mobile.

7. Deploy and Wrap-up

  1. Save style.css next to index.html
  2. Add <link rel="stylesheet" href="style.css"> in <head>
  3. Commit both files on GitHub
  4. Vercel auto-deploys in ~30 seconds

What is next

Next lesson, you stop uploading files through the GitHub web UI and start working like a developer — with git in your terminal.

🛠 Mini Projects

Style your homepage with a clear hero section, a card grid of projects, and a footer
Add a dark-mode toggle using prefers-color-scheme
Create a second page (e.g. about.html) and share style.css between both
Example code / lecture materials

All lecture materials and example code are openly available on GitHub.

View on GitHub ↗