From Zero to Senior · The LabالعربيةGitHub

Chapter 6

CSS: Styling a Page

5 examples · 3 projects · 5 exercises

In this chapter you will learn to

  • write CSS rules and connect a stylesheet to a page
  • choose elements with type, class and id selectors
  • use colours, fonts and units like a professional
  • understand the box model: content, padding, border and margin
  • turn your plain profile page into a beautiful one

Examples

Here’s the before-and-after we are aiming for. Same HTML, plus one CSS file. When I first saw what CSS can do, my antenna lit up!

profile.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="style.css">
    <title>About Sara</title>
  </head>
  <body>
    <header>
      <img src="bit.svg" alt="Sara’s avatar: a smiling purple robot" width="90" height="105">
      <h1>Sara Khan</h1>
      <p>Beginner web developer from Alexandria</p>
      <nav>
        <a href="#about">About</a> |
        <a href="#skills">Skills</a> |
        <a href="#contact">Contact</a>
      </nav>
    </header>

    <main>
      <section id="about">
        <h2>About me</h2>
        <p>I started learning to code this year with <em>Code from Zero</em>. I love building small tools that make life easier.</p>
      </section>

      <section id="skills">
        <h2>Skills I am learning</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Write to me at <a href="mailto:sara@example.com">sara@example.com</a>.</p>
      </section>
    </main>

    <footer>
      <p>Built by Sara, with HTML and CSS.</p>
    </footer>
  </body>
</html>
profile.html560px
Figure 6.1: The profile page from Chapter 5 at the end of this chapter. Compare it with Figure 5.9: the HTML has not changed at all.

6.3 Selectors: choosing what to style

The selector decides which elements a rule applies to. Four kinds of selector cover almost everything you need:

selectors.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Selectors</title>
    <style>
      h1 {
        color: #4338ca;
      }
      .intro {
        font-style: italic;
      }
      #featured {
        background-color: #fef3c7;
      }
      li .badge {
        color: white;
        background-color: #db2777;
        font-size: 0.8rem;
      }
    </style>
  </head>
  <body>
    <h1>Bit’s reading list</h1>
    <p class="intro">Books that every new developer should read.</p>
    <ul>
        <li id="featured">Code from Zero <span class="badge">New</span></li>
        <li>Senior Frontend Engineering</li>
        <li>Senior Backend Engineering</li>
    </ul>
    <p>This list is updated every month.</p>
  </body>
</html>
selectors.html560px
Figure 6.3: Each rule styles a different set of elements.

6.4 Colours

CSS understands colours in several formats:

colors.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Colours</title>
    <style>
      p {
        padding: 8px;
        color: white;
      }
      .named { background-color: tomato; }
      .hex { background-color: #4338ca; }
      .rgb { background-color: rgb(15, 118, 110); }
      .alpha { background-color: rgba(67, 56, 202, 0.4); color: black; }
    </style>
  </head>
  <body>
    <h1>Colours</h1>
    <p class="named">Named: tomato</p>
    <p class="hex">Hex: #4338ca</p>
    <p class="rgb">RGB: rgb(15, 118, 110)</p>
    <p class="alpha">With transparency</p>
  </body>
</html>
colors.html560px
Figure 6.4: Four ways to write a colour.

6.6 The box model

Here is the most important idea in CSS layout: every element is a rectangular box. Headings, paragraphs, images and links are all boxes, and every box has four layers:

box.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Box model</title>
    <style>
      .box {
        width: 260px;
        padding: 20px;
        border: 6px solid #4338ca;
        margin: 30px;
        background-color: #eef2ff;
      }
    </style>
  </head>
  <body>
    <div class="box">I am a box with padding, a border and a margin.</div>
  </body>
</html>
box.html560px
Figure 6.6: A box with 20px padding, a 6px border and a 30px margin.

6.8 Project: style your profile

Here is the complete stylesheet for the page in Figure 6.1. It is organised in five commented parts, like the stylesheets professionals write. Type it part by part, and reload the page after each part to see what it does.

style.css⤓ File
/* 1. Colours and fonts for the whole page */
:root {
  --brand: #4338ca;
  --accent: #db2777;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  line-height: 1.6;
  color: #1e1b2e;
  background-color: #f5f5fb;
}

/* 2. The header: a coloured band with the avatar */
header {
  text-align: center;
  padding: 32px 16px 24px;
  color: white;
  background-color: var(--brand);
}

header img {
  background-color: white;
  border-radius: 50%;
  padding: 8px;
}

header h1 {
  margin: 8px 0 0;
  font-size: 2rem;
}

header p {
  margin: 0 0 16px;
  opacity: 0.85;
}

/* 3. The menu: links that look like buttons */
nav a {
  display: inline-block;
  padding: 6px 16px;
  margin: 4px;
  border-radius: 999px;
  color: var(--brand);
  background-color: white;
  text-decoration: none;
  font-weight: 700;
}

/* 4. The content: white cards, centred */
main {
  max-width: 640px;
  margin: 24px auto;
  padding: 0 16px;
}

section {
  background-color: white;
  border-radius: 16px;
  padding: 8px 24px 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(30, 27, 46, 0.08);
}

h2 {
  color: var(--brand);
  border-bottom: 3px solid var(--soft);
  padding-bottom: 4px;
}

/* 5. Skills as coloured tags */
ul {
  padding: 0;
}

li {
  display: inline-block;
  list-style: none;
  padding: 4px 14px;
  margin: 4px;
  border-radius: 999px;
  color: white;
  background-color: var(--accent);
}

a {
  color: var(--accent);
}

footer {
  text-align: center;
  color: #5b5873;
  font-size: 0.9rem;
  padding-bottom: 24px;
}
+ 1 files
bit.svg⤓ File

Practice projects

Project 6.1 · Easy

A warm recipe page

Give the recipe page the warm look of a cookbook: a cream background, a serif font, and orange accents.

You will practise: linking a stylesheet, type selectors, colours, fonts, line-height and borders.

Steps
  1. Create recipe.css and link it in the <head> of recipe.html.
  2. On body, set a cream background (#fdf6ec), a dark brown text colour, a serif font such as Georgia, and line-height: 1.6.
  3. Make the h1 bigger and orange. Turn the h2s into small capitals with text-transform: uppercase, some letter-spacing, and a coloured border-bottom.
  4. Round the corners of the picture and give it a white frame with padding and background-color.
  5. Colour the strong text so the cooking time stands out.

Hint: padding on an image shows its background colour around it, like a photo frame. Try border-radius: 16px and see the frame’s corners round.

Solution
recipe.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="recipe.css">
    <title>Lentil Soup</title>
  </head>
  <body>
    <h1>Grandma’s Lentil Soup</h1>
    <img src="soup.svg" alt="A bowl of orange lentil soup with lemon" width="160" height="120">
    <p>A warm, simple soup ready in <strong>30 minutes</strong>. Serves four.</p>

    <h2>Ingredients</h2>
    <ul>
      <li>1 cup of red lentils</li>
      <li>1 onion, chopped</li>
      <li>1 carrot, chopped</li>
      <li>1 teaspoon of cumin</li>
      <li>5 cups of water</li>
      <li>Salt and lemon</li>
    </ul>

    <h2>Steps</h2>
    <ol>
      <li>Wash the lentils.</li>
      <li>Cook the onion and carrot in a little oil for 5 minutes.</li>
      <li>Add the lentils, cumin and water, and boil for 20 minutes.</li>
      <li>Blend until smooth, add salt, and serve with lemon.</li>
    </ol>
  </body>
</html>
recipe.html520px
Project 6.1: the recipe page with its own stylesheet.
recipe.css⤓ File
body {
  margin: 0;
  padding: 24px;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.6;
  color: #3b2f2f;
  background-color: #fdf6ec;
}

h1 {
  font-size: 2rem;
  color: #b45309;
  margin-bottom: 8px;
}

img {
  background-color: white;
  border-radius: 16px;
  padding: 8px;
}

h2 {
  font-family: system-ui, sans-serif;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #92400e;
  border-bottom: 2px solid #fcd34d;
  padding-bottom: 4px;
}

li {
  margin-bottom: 6px;
}

strong {
  color: #b45309;
}

Project 6.2 · Medium

A café brand with custom properties

Give the café website a brand: three colours defined once as custom properties, used everywhere.

You will practise: custom properties, the box model, inline-block pills, cards and centring with max-width.

Steps
  1. In cafe.css, define --brown, --cream and --gold in :root.
  2. Make the header a brown band with centred white text, and turn the menu links into cream pills with display: inline-block, padding and border-radius: 999px.
  3. Keep main narrow and centred with max-width: 560px and margin: 24px auto.
  4. Turn each section into a white card with rounded corners and a gold top border.
  5. Finally, change only the three custom properties to a completely different palette, and watch the whole site change.

Hint: if a pill looks squashed, check that it has display: inline-block; plain inline links ignore vertical padding in the layout.

Solution
cafe.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="cafe.css">
    <title>Bean & Book Café</title>
  </head>
  <body>
    <header>
      <h1>Bean &amp; Book Café</h1>
      <p>Coffee, cake and a quiet corner to read.</p>
      <nav>
        <a href="#menu">Menu</a> |
        <a href="#hours">Opening hours</a> |
        <a href="#find">Find us</a>
      </nav>
    </header>

    <main>
      <section id="menu">
        <h2>Menu</h2>
        <ul>
          <li>Coffee: 30</li>
          <li>Tea with mint: 15</li>
          <li>Chocolate cake: 45</li>
        </ul>
      </section>
      <section id="hours">
        <h2>Opening hours</h2>
        <ul>
          <li>Saturday to Thursday: 8:00 to 22:00</li>
          <li>Friday: 14:00 to 23:00</li>
        </ul>
      </section>
      <section id="find">
        <h2>Find us</h2>
        <p>12 Library Street, Alexandria. Call us on <a href="tel:+201000000000">010 0000 0000</a>.</p>
      </section>
    </main>

    <footer>
      <p>© 2026 Bean &amp; Book Café</p>
    </footer>
  </body>
</html>
cafe.html520px
Project 6.2: the café website with a brand.
cafe.css⤓ File
:root {
  --brown: #6b4423;
  --cream: #fff8ee;
  --gold: #d97706;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: #2b2118;
  background-color: var(--cream);
  line-height: 1.6;
}

header {
  text-align: center;
  padding: 32px 16px;
  color: white;
  background-color: var(--brown);
}

header h1 {
  margin: 0;
}

nav a {
  display: inline-block;
  margin: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--brown);
  background-color: var(--cream);
  text-decoration: none;
  font-weight: 700;
}

main {
  max-width: 560px;
  margin: 24px auto;
  padding: 0 16px;
}

section {
  background-color: white;
  border-radius: 14px;
  padding: 4px 20px 12px;
  margin-bottom: 16px;
  border-top: 4px solid var(--gold);
}

h2 {
  color: var(--brown);
}

a {
  color: var(--gold);
}

footer {
  text-align: center;
  font-size: 0.9rem;
  padding: 16px;
  color: var(--brown);
}

Project 6.3 · Challenge

A professional sign-up form

Turn the plain sign-up form into a clean card that is pleasant to fill in, with clear focus states.

You will practise: box-sizing, styling form fields, attribute selectors, :focus and box-shadow.

Steps
  1. Start signup.css with the box-sizing: border-box rule from Section 6.6, so that fields with padding never overflow.
  2. Turn the form into a white card with a soft shadow and a max-width, on a light background.
  3. Style input, select and textarea together, with one selector list: full width, padding, a border and rounded corners. Use font: inherit so they use the page’s font.
  4. The checkbox should not be full width: select it with the attribute selector input[type="checkbox"] and set width: auto.
  5. Add a clear focus style: a coloured border and a soft “glow” made with box-shadow: 0 0 0 3px. Click into each field to test it.

Hint: never remove the focus outline without replacing it with something just as visible; keyboard users need to see where they are. Chapter 16 explains why.

Solution
signup.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="signup.css">
    <title>Course sign-up</title>
  </head>
  <body>
    <form>
      <h1>Join the web course</h1>
      <p>
        <label for="name">Full name</label><br>
        <input id="name" type="text" required>
      </p>
      <p>
        <label for="email">Email</label><br>
        <input id="email" type="email" required>
      </p>
      <p>
        <label for="phone">Phone</label><br>
        <input id="phone" type="tel">
      </p>
      <p>
        <label for="level">Your level</label><br>
        <select id="level">
        <option>Complete beginner</option>
        <option>I know some HTML</option>
        <option>I know HTML and CSS</option>
        </select>
      </p>
      <p>
        <label for="why">Why do you want to learn?</label><br>
        <textarea id="why" rows="3" cols="40"></textarea>
      </p>
      <p>
        <input id="agree" type="checkbox">
        <label for="agree">I agree to receive emails about the course</label>
      </p>
      <button type="submit">Sign me up</button>
    </form>
  </body>
</html>
signup.html520px
Project 6.3: the sign-up form as a styled card.
signup.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  background-color: #eef2ff;
  color: #1e1b2e;
}

form {
  max-width: 420px;
  padding: 8px 24px 24px;
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(30, 27, 46, 0.1);
}

h1 {
  color: #4338ca;
}

label {
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 10px;
}

input[type="checkbox"] {
  width: auto;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #4338ca;
  box-shadow: 0 0 0 3px #c7d2fe;
}

button {
  padding: 10px 24px;
  font: inherit;
  font-weight: 700;
  color: white;
  background-color: #4338ca;
  border: 0;
  border-radius: 999px;
}
+ 1 files
soup.svg⤓ File

Exercises

Exercise 6.1 · Easy

Give the profile page’s footer a dark background and white text.
The book's short answer
footer { background-color: #1e1b2e; color: white; padding: 16px; }
Show the solution
profile.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../examples/style.css">
    <!-- The chapter's stylesheet first, then only what this exercise changes. -->
    <link rel="stylesheet" href="footer.css">
    <title>About Sara</title>
  </head>
  <body>
    <header>
      <img src="../../examples/bit.svg" alt="Sara’s avatar: a smiling purple robot" width="90" height="105">
      <h1>Sara Khan</h1>
      <p>Beginner web developer from Alexandria</p>
      <nav>
        <a href="#about">About</a> |
        <a href="#skills">Skills</a> |
        <a href="#contact">Contact</a>
      </nav>
    </header>

    <main>
      <section id="about">
        <h2>About me</h2>
        <p>I started learning to code this year with <em>Code from Zero</em>. I love building small tools that make life easier.</p>
      </section>

      <section id="skills">
        <h2>Skills I am learning</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Write to me at <a href="mailto:sara@example.com">sara@example.com</a>.</p>
      </section>
    </main>

    <footer>
      <p>Built by Sara, with HTML and CSS.</p>
    </footer>
  </body>
</html>
profile.html640px
footer.css⤓ File
/* A dark footer with white text */
footer {
  background-color: #1e1b2e;
  color: white;
  padding: 16px;
}

Exercise 6.2 · Easy

Make the links in the Contact section bold, and remove their underline only when the mouse is over them. (Search MDN for the :hover pseudo-class.)
The book's short answer
#contact a { font-weight: 700; } #contact a:hover { text-decoration: none; }
Show the solution
profile.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../examples/style.css">
    <link rel="stylesheet" href="contact.css">
    <title>About Sara</title>
  </head>
  <body>
    <header>
      <img src="../../examples/bit.svg" alt="Sara’s avatar: a smiling purple robot" width="90" height="105">
      <h1>Sara Khan</h1>
      <p>Beginner web developer from Alexandria</p>
      <nav>
        <a href="#about">About</a> |
        <a href="#skills">Skills</a> |
        <a href="#contact">Contact</a>
      </nav>
    </header>

    <main>
      <section id="about">
        <h2>About me</h2>
        <p>I started learning to code this year with <em>Code from Zero</em>. I love building small tools that make life easier.</p>
      </section>

      <section id="skills">
        <h2>Skills I am learning</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Write to me at <a href="mailto:sara@example.com">sara@example.com</a>.</p>
      </section>
    </main>

    <footer>
      <p>Built by Sara, with HTML and CSS.</p>
    </footer>
  </body>
</html>
profile.html640px
contact.css⤓ File
/* Bold links in the Contact section only (#contact is the section's id). */
#contact a {
  font-weight: 700;
}

/* :hover applies only while the mouse is over the link. */
#contact a:hover {
  text-decoration: none;
}

Exercise 6.3 · Medium

Add a class="highlight" to one skill and write a rule that gives it a different colour from the others.
The book's short answer
li.highlight { background-color: #0f766e; }
Show the solution
profile.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../examples/style.css">
    <link rel="stylesheet" href="highlight.css">
    <title>About Sara</title>
  </head>
  <body>
    <header>
      <img src="../../examples/bit.svg" alt="Sara’s avatar: a smiling purple robot" width="90" height="105">
      <h1>Sara Khan</h1>
      <p>Beginner web developer from Alexandria</p>
      <nav>
        <a href="#about">About</a> |
        <a href="#skills">Skills</a> |
        <a href="#contact">Contact</a>
      </nav>
    </header>

    <main>
      <section id="about">
        <h2>About me</h2>
        <p>I started learning to code this year with <em>Code from Zero</em>. I love building small tools that make life easier.</p>
      </section>

      <section id="skills">
        <h2>Skills I am learning</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li class="highlight">JavaScript</li>
        </ul>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Write to me at <a href="mailto:sara@example.com">sara@example.com</a>.</p>
      </section>
    </main>

    <footer>
      <p>Built by Sara, with HTML and CSS.</p>
    </footer>
  </body>
</html>
profile.html640px
highlight.css⤓ File
/* li.highlight is more specific than li, so it wins even though both set the background. */
li.highlight {
  background-color: #0f766e;
}

Exercise 6.4 · Medium

Style the recipe page from Chapter 5’s exercises with its own stylesheet. Use at least one custom property.
The book's short answer
Any stylesheet that defines a variable in :root and uses it with var().
Show the solution
recipe.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Ful Medames</title>
    <link rel="stylesheet" href="recipe.css">
  </head>
  <body>
    <h1>Ful Medames for Breakfast</h1>
    <!-- A good alt describes what the picture shows, for someone who cannot see it. -->
    <img src="../../../ch05/exercises/ex3/ful.svg" alt="A clay bowl of mashed fava beans topped with olive oil, cumin and chopped tomato" width="200" height="140">
    <p>Ready in <strong>10 minutes</strong>. Serves two.</p>

    <h2>Ingredients</h2>
    <ul>
      <li>1 can of cooked fava beans</li>
      <li>2 tablespoons of olive oil</li>
      <li>1 lemon</li>
      <li>1 clove of garlic, crushed</li>
      <li>1/2 teaspoon of cumin and a pinch of salt</li>
      <li>1 tomato, chopped</li>
    </ul>

    <h2>Steps</h2>
    <ol>
      <li>Warm the beans with a little of their water for 5 minutes.</li>
      <li>Mash them with a fork, leaving some whole.</li>
      <li>Stir in the garlic, cumin, salt and the juice of the lemon.</li>
      <li>Put it in a bowl, pour the oil over it and add the tomato.</li>
    </ol>
  </body>
</html>
recipe.html640px
recipe.css⤓ File
/* Custom properties: the recipe's colours, defined once and used everywhere. */
:root {
  --bean: #92400e;
  --oil: #ca8a04;
  --paper: #fffbeb;
}

body {
  max-width: 600px;
  margin: 24px auto;
  padding: 0 16px;
  font-family: Georgia, serif;
  line-height: 1.6;
  color: #292524;
  background-color: var(--paper);
}

h1 {
  color: var(--bean);
  border-bottom: 4px solid var(--oil);
}

h2 {
  color: var(--bean);
}

img {
  display: block;
  margin: 16px auto;
}

ol li::marker {
  color: var(--oil);
  font-weight: 700;
}

Exercise 6.5 · Challenge

Open your profile page in DevTools and switch on the device toolbar (the phone icon). Make the page look good at 360 pixels wide. What do you need to change?
The book's short answer
Usually: smaller padding on the header, a smaller h1, less padding inside the cards, and making sure no fixed width is wider than the screen.
Show the solution
profile.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../examples/style.css">
    <link rel="stylesheet" href="mobile.css">
    <title>About Sara</title>
  </head>
  <body>
    <header>
      <img src="../../examples/bit.svg" alt="Sara’s avatar: a smiling purple robot" width="90" height="105">
      <h1>Sara Khan</h1>
      <p>Beginner web developer from Alexandria</p>
      <nav>
        <a href="#about">About</a> |
        <a href="#skills">Skills</a> |
        <a href="#contact">Contact</a>
      </nav>
    </header>

    <main>
      <section id="about">
        <h2>About me</h2>
        <p>I started learning to code this year with <em>Code from Zero</em>. I love building small tools that make life easier.</p>
      </section>

      <section id="skills">
        <h2>Skills I am learning</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Write to me at <a href="mailto:sara@example.com">sara@example.com</a>.</p>
      </section>
    </main>

    <footer>
      <p>Built by Sara, with HTML and CSS.</p>
    </footer>
  </body>
</html>
profile.html640px
mobile.css⤓ File
/* Only on screens 400 pixels wide or narrower (a phone held upright). */
@media (max-width: 400px) {
  header {
    padding: 20px 8px 16px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  nav a {
    padding: 4px 12px;
    margin: 2px;
  }

  main {
    padding: 0 8px;
  }

  section {
    padding: 4px 14px 12px;
  }

  /* Long words such as e-mail addresses may break instead of widening the page. */
  p {
    overflow-wrap: anywhere;
  }
}