We’re moving to a new home! Our website is currently in test mode while we update and transfer our content. Some pages and resources may be temporarily unavailable. We’ll be back with all resources shortly. Thank you for your patience.

HTML & CSS | 03 CSS FOUNDATIONS

Put your HTML skills to work

Style, debug and refine a small website using selectors, the cascade, typography and the box model. Try each challenge before opening its hint or sample solution.

YOUR CHALLENGE ROUTE

From your first stylesheet to a consistent website

Work in your editor and browser. Start with the foundation challenges, then move on to repair tasks and the final project. You can spread the work across several lessons.

Use fictional details and images you own or are allowed to publish. Use your existing HTML pages or create a simple fictional club page. Keep semantic structure and focus on CSS foundations; advanced layout comes next.

0 / 8 challenges checked.

Your checks last while this page is open. They record your self-review, not an automatic code score.

CHALLENGE 01 | FOUNDATION

One stylesheet, two pages

Use 03.1 | External stylesheets

Create css/styles.css inside your club project. Link it from index.html and projects.html, which should both sit beside the css folder. Give body text a readable font stack and give main headings a shared colour.

Success criteria

  • Each page links the same external stylesheet from head.
  • The path matches the folder structure.
  • The CSS file contains no HTML style tags.
  • Changing the heading colour once updates both pages after saving and refreshing.
Need a hint?

From these two HTML files, the path is css/styles.css. The link needs rel="stylesheet" and href.

Reveal a sample solution
<!-- In the head of both HTML pages -->
<link rel="stylesheet" href="css/styles.css">
/* css/styles.css */
body {
  font-family: Arial, Helvetica, sans-serif;
  color: #24363a;
  line-height: 1.6;
}
h1 {
  color: #176c65;
}

Save both files and refresh. If styling fails, inspect the path, filename case and declarations.

CHALLENGE 02 | BUILD

Choose selectors that match your intention

Use 03.1 | Classes, IDs and descendants

Add two project articles using class="project-card". Give one paragraph in each article class="notice". Add a separate joining section with id="join". Style all cards, notice paragraphs inside cards and the single joining section.

Success criteria

  • Reusable cards share a class rather than a repeated id.
  • The joining id is unique.
  • Use .project-card to target cards.
  • Use .project-card p.notice to target only the specified paragraphs inside cards.
  • A notice paragraph outside a card is unaffected by that descendant rule.
Need a hint?

A dot targets a class; # targets an id. A space expresses a descendant relationship. p.notice means the paragraph itself has the class.

Reveal a sample solution
.project-card {
  border: 2px solid #24988f;
  padding: 16px;
}
.project-card p.notice {
  background-color: #eaf7f5;
  font-weight: 700;
}
#join {
  padding: 20px;
}

The descendant rule matches only paragraphs with the notice class that are nested within a project-card element.

CHALLENGE 03 | TRACE

Predict the winning colour

Use 03.2 | Specificity and source order

Assume these are normal, unlayered author declarations and no other colour rules apply. Predict the paragraph’s colour. Then remove the ID rule and predict again. Finally remove the class from the paragraph and predict once more.

<p id="announcement" class="notice">Friday meeting</p>
p { color: green; }
.notice { color: purple; }
#announcement { color: navy; }
p { color: maroon; }

Success criteria

  • Explain the first result using specificity.
  • Explain why the later p rule does not beat the class rule.
  • Explain the final result using a source-order tie.
  • Confirm each prediction in the browser.
Need a hint?

Compare IDs, classes and element types in that order. Source order breaks a tie only after higher-priority factors are equal.

Reveal a sample solution

First: navy, because the ID selector has the greatest specificity. After removing the ID rule: purple, because .notice beats both type selectors. After also removing the notice class: maroon, because the two p rules tie and the later one wins.

These conclusions depend on the stated ordinary author-CSS conditions.

CHALLENGE 04 | INVESTIGATE

Separate inheritance from direct styling

Use 03.2 | Inheritance

Predict which styles the child paragraph receives in the example below. Then remove its direct colour declaration and explain the change.

<section class="club-info">
  <p>Our next project is a delivery robot.</p>
</section>
.club-info {
  color: green;
  font-family: Arial, sans-serif;
  border: 2px solid green;
  padding: 20px;
}
p { color: purple; }

Success criteria

  • Identify the paragraph’s original colour.
  • Explain which font it inherits.
  • Explain why it does not automatically get its own border or padding.
  • Describe the result after removing the direct colour declaration.
Need a hint?

The parent class rule and child type rule target different elements. The child’s direct colour does not compete with the parent selector’s specificity.

Reveal a sample solution

The paragraph is purple because its own declaration sets the colour. It inherits the parent’s font family. Border and padding normally do not inherit, although the parent’s padding still creates space around its content.

Remove p { color: purple; } and the paragraph inherits green. You could also explicitly request the parent’s colour with color: inherit.

CHALLENGE 05 | DESIGN

Create a readable text system

Use 03.3 | Typography and colour

Style your club’s main text, headings, links and short labels. Choose a font stack, relative sizes, comfortable line height and suitable foreground/background pairs. Test with enlarged text.

Success criteria

  • Use a generic font-family fallback.
  • Use a consistent heading scale and readable body text.
  • Keep links visibly identifiable and focus indicators intact.
  • Reserve uppercase for short labels rather than long paragraphs.
  • Check actual text/background contrast with a tool.
  • Explain what happens to 2rem when the root font size changes.
Need a hint?

rem depends on the root font size. A unitless line height scales with the element’s own text size. A colour suitable for borders may not suit small text on white.

Reveal a sample solution
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: #24363a;
  background-color: #ffffff;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
a { color: #176c65; text-decoration: underline; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.04em; }

If the root font size is 16 CSS pixels, 2rem is 32 CSS pixels. If it becomes 20 CSS pixels, 2rem becomes 40 CSS pixels. Check the actual rendered colours, sizes and states rather than assuming the sample meets every accessibility need.

CHALLENGE 06 | CALCULATE

Calculate the real width

Use 03.4 | Content-box and border-box

A card has width: 280px, padding: 18px, border: 3px solid and margin: 12px on every side. Calculate the content width, border-box width and horizontal sum including margins for both sizing models.

Success criteria

  • Show the left and right padding and border separately or as doubled values.
  • Keep margin outside the specified width in both models.
  • Explain which width stays at 280px in each model.
  • Check your results using developer tools.
Need a hint?

For content-box, add padding and border to the specified width. For border-box, subtract them to find content width. Add horizontal margins only after finding the border-box width.

Reveal a sample solution
content-box:
Content width = 280px
Border-box width = 280 + 18 + 18 + 3 + 3 = 322px
Sum with margins = 322 + 12 + 12 = 346px

border-box:
Border-box width = 280px
Content width = 280 - 18 - 18 - 3 - 3 = 238px
Sum with margins = 280 + 12 + 12 = 304px

These are fixed-width calculations without other size constraints. Actual positioning also depends on the layout.

CHALLENGE 07 | DEBUG

Repair a card that overflows and clips text

Use 03.3 and 03.4 | Readability and sizing

Assume the card sits inside a narrow container and uses content-box sizing. Explain the risks in this rule, then replace it with an adaptable version.

.project-card {
  width: 100%;
  padding: 30px;
  border: 4px solid #24988f;
  height: 100px;
  overflow: hidden;
  font-size: 10px;
}

Success criteria

  • Keep padding and border within the full width.
  • Allow the card to grow with its content.
  • Remove clipping caused by an unnecessary fixed height and hidden overflow.
  • Use readable text sizing.
  • Add consistent external spacing and a suitable width cap.
Need a hint?

With content-box, 100% content width plus padding and borders can exceed the containing width. Fixed height and hidden overflow can hide enlarged or longer text.

Reveal a sample solution
.project-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 640px;
  padding: 20px;
  border: 2px solid #24988f;
  margin: 24px auto;
  font-size: 1rem;
  line-height: 1.6;
}

The card grows naturally because the fixed height is removed. Auto horizontal margins can centre it when spare width exists. Test long content, enlarged text and a narrow viewport.

CHALLENGE 08 | STRETCH

Refine a consistent three-page website

Combine 03.1 to 03.4

Apply one shared stylesheet to your three-page club website. Create a consistent visual identity using the foundations from this section. Keep the layout simple; Flexbox and Grid come next.

Success criteria

  • Every page links the same CSS file correctly.
  • Shared components use reusable classes.
  • Ids remain unique and unnecessary overrides are removed.
  • Body text, headings and links have consistent readable styles.
  • Cards use deliberate padding, borders and margins.
  • Sizing works on narrow screens and with enlarged text.
  • Keyboard focus remains visible.
  • You can explain one cascade decision and one width calculation.
Need a hint?

Build a small set of reusable rules rather than a different style for every paragraph. Inspect surprises before adding !important.

Reveal a sample solution

One possible stylesheet plan

  • Base styles: body font, text colour, background and line height.
  • Type styles: heading sizes, captions and recognisable links.
  • Components: project-card, notice and short section labels.
  • Sizing: consistent border-box rules and capped full-width cards.
*, *::before, *::after {
  box-sizing: border-box;
}
.project-card {
  width: 100%;
  max-width: 640px;
  margin: 24px auto;
  padding: 20px;
  border: 2px solid #24988f;
}

There is no single correct design. Submit your HTML and CSS files, screenshots and a short explanation of the choices you made. A partner should be able to identify shared components and read the pages comfortably.

REFLECT AND CONTINUE

Explain your CSS decisions

Record one selector choice, one cascade result, one typography improvement and one box-model calculation. Describe a change you made after testing.

Keep your files. Next, use Flexbox and Grid to arrange the components you have styled.