← Web design from scratch

Style your page with CSS

You’ve built the structure of your first website. Now we’ll turn that HTML skeleton into a clearer, better organised page with a professional look.

Level · Beginner Time · 30–40 min Path · Web design

01

Start with the global styles

Before styling each section, set a few basic rules for the entire page.

Open your project’s styles.css file and start with this code.

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  color: #222222;
  background: #ffffff;
  line-height: 1.6;
}

These rules remove the browser’s default page margin and give the page a consistent starting point.

box-sizing: border-box makes sizing easier by including padding and borders in the total width of an element.

02

Style the navigation

Start by arranging the navigation menu you built in the previous lesson.

nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 25px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

This example introduces several new properties.

01

max-width limits how wide the content can get.

02

margin: 0 auto centres the block horizontally.

03

display: flex lets you arrange the items in a flexible layout.

04

justify-content: space-between pushes the outer items to opposite ends and distributes the space between items.

03

Style the links

Browsers underline links by default. You can change how the links in your navigation look.

nav a {
  color: #222222;
  text-decoration: none;
  margin-left: 20px;
}

You can also define how a link changes when you hover over it.

nav a:hover {
  opacity: 0.6;
}

This small change gives visitors visual feedback.

04

Style the hero section

Give the first section enough space so the main message stands out.

main > section:first-child {
  max-width: 1200px;
  margin: 0 auto;
  padding: 120px 30px;
}

Next, style the main heading.

h1 {
  max-width: 850px;
  margin: 0 0 30px;
  font-size: 64px;
  line-height: 1.05;
  font-weight: 400;
}
White space is part of the design. Leave room around the content so it’s easier to read.

05

Create a button

You can style the hero link as a button so the main action stands out.

Add a class to the link in HTML.

<a href="#services" class="button">
  View services
</a>

Then add these rules in CSS.

.button {
  display: inline-block;
  margin-top: 20px;
  padding: 15px 25px;
  background: #222222;
  color: #ffffff;
  text-decoration: none;
}

The class applies these styles only to elements that use it.

06

Give the sections room

A website is easier to read when there’s enough space between sections.

section {
  padding: 90px 30px;
}

section > h2,
section > p,
section > article {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

You can set one section apart with a different background.

#about {
  background: #f5f2ec;
}

07

Turn the services into cards

In the previous lesson, you used article elements for your services.

Style each article as a card.

#services article {
  margin-top: 20px;
  padding: 30px;
  border: 1px solid #dddddd;
}

You can also refine the card headings.

#services h3 {
  margin-top: 0;
  font-size: 26px;
  font-weight: 400;
}

Clear headings and consistent spacing help even a simple design look professional.

08

Style the contact section

Help the final call to action stand out from the rest of the page.

#contact {
  text-align: center;
  background: #222222;
  color: #ffffff;
}

Style the link in this section too.

#contact a {
  display: inline-block;
  margin-top: 20px;
  padding: 15px 25px;
  background: #ffffff;
  color: #222222;
  text-decoration: none;
}

09

Finish with the footer

Keep the footer simple.

footer {
  padding: 35px 30px;
  text-align: center;
  border-top: 1px solid #dddddd;
}

footer p {
  margin: 0;
  font-size: 14px;
}

10

Keep your design consistent

When you’re starting out with CSS, it’s tempting to add lots of colours, shadows, borders and effects.

Start by making a few design choices and applying them consistently.

01

Use a limited colour palette.

02

Keep heading sizes consistent.

03

Use the same spacing between sections.

04

Use the same style for buttons that serve similar purposes.

05

Prioritise readability.

A professional design can be simple. Give each element a purpose and make it clear what visitors should read or do first.

What you’ve learned

  • How to set global styles for a website.
  • How to control content width with max-width.
  • How to centre blocks with auto margins.
  • How to use Flexbox in navigation.
  • How to style headings and sections.
  • How to use classes to style links as buttons.
  • How to turn content into cards.
  • How to distinguish sections with background colours.
  • How to design a simple footer.
  • Why consistent design choices matter.

Style the website you built

Open your my-first-website project and work with the structure you built in Lesson 05.

  1. Set global styles on the body.
  2. Style the navigation.
  3. Limit the width of the content.
  4. Add space around the hero section.
  5. Style the h1 heading.
  6. Style a link as a button.
  7. Give one section a different background.
  8. Style the services as cards.
  9. Style the contact section.
  10. Style the footer.

Adjust some sizes, spacing and colours to make the design your own.

Check what happens when you make the browser window narrower. Some elements may become harder to read or use. In the next lesson, you’ll learn how to adapt the layout to smaller screens.

PREVIOUS LESSON

← 05 · Build the structure of your first page