// CSS Course — Chapter Exercises

CSS
Exercises

One set of exercises per chapter. Work through them in the Playground after studying each chapter. Exercises progress from Easy to Challenging — the final exercise in each set combines all chapter concepts.

12 Chapters 96 Exercises Easy → Challenging Live Preview
Chapter 01

Selectors & Specificity

Practise targeting elements precisely and understanding which rules win when two conflict.

8 Exercises
EX 01
Your First CSS Rule
Easy
+
Task

Link a CSS file to an HTML page and write three basic CSS rules using element selectors. Style the body background, the h1 colour, and the p font-size.

  • body background: #0a0a0f
  • h1 colour: #7c6af7
  • p font-size: 1rem
Expected CSS
body { }h1 { }p { }element selectors
✓ Success Criteria
  • CSS file is linked in <head> with <link rel="stylesheet">
  • All three rules present with correct property values
  • Page background is dark, heading is purple, paragraph uses rem units
EX 02
Class and ID Selectors
Easy
+
Task

Create a card component using a class selector, and a unique hero section using an ID selector. Style them differently and explain in a comment why you chose each selector type.

  • HTML: <div class="card"> with padding, background, border-radius
  • HTML: <section id="hero"> with min-height and different background
✓ Success Criteria
  • .card class applied to 3 elements — all styled identically
  • #hero applies to exactly one element
  • Comment explains: classes = reusable, IDs = unique elements
EX 03
Combinator Selectors
Easy
+
Task

Style a navigation using all four combinators. Each rule must use a different combinator.

  • Descendant: style all links inside nav
  • Child: style only direct li children of ul
  • Adjacent sibling: style p immediately after h2
  • General sibling: style all p siblings after h2
✓ Success Criteria
  • 4 CSS rules — one per combinator type
  • Comments above each rule identify the combinator being used
  • Visual difference confirms correct targeting
EX 04
Attribute Selectors
Easy
+
Task

Style form inputs differently based on their type attribute — without adding any extra classes to the HTML.

  • input[type="text"] — blue border
  • input[type="email"] — green border
  • input[type="password"] — orange border
  • a[href^="https"] — teal colour
✓ Success Criteria
  • 4 attribute selectors present with correct syntax
  • Each input type has a visually distinct border colour
  • Zero extra classes added to HTML
EX 05
Specificity Battle
Medium
+
Task

Write 4 CSS rules targeting the same paragraph. Predict which colour will win before running. Then verify your prediction in the playground.

Starter Code
/* Rule 1 */
p               { color: red; }
/* Rule 2 */
.intro          { color: blue; }
/* Rule 3 */
div .intro      { color: green; }
/* Rule 4 */
#main .intro p { color: orange; }
✓ Success Criteria
  • Orange wins — #main .intro p has score 0,1,1,1
  • Add a comment above each rule with its specificity score: (inline, ID, class, element)
  • Demonstrate you understand by reordering the rules — confirm orange still wins regardless of order
EX 06
Style Without !important
Medium
+
Task

The CSS below uses !important everywhere. Rewrite it to achieve the same visual result without using !important even once. Fix the specificity instead.

Starter Code (rewrite without !important)
p        { color: gray !important; }
.card p  { color: white !important; }
.card    { background: #111 !important; }
nav a    { color: #888 !important; }
nav a:hover { color: white !important; }
✓ Success Criteria
  • Zero !important declarations
  • Same visual result as the original
  • Comments explain how specificity is controlled instead
EX 07
The Cascade: Order Matters When Scores Tie
Medium
+
Task

Write 3 CSS rules with identical specificity (all class selectors, same score). Observe that the last rule wins — the cascade order. Then demonstrate this by moving the winning rule to the top — confirm the result changes.

✓ Success Criteria
  • 3 class rules with equal specificity scores
  • The last declared rule wins when specificity ties
  • Demonstrated by moving rules and observing the change
EX 08
Style a Full Navigation Bar
Challenging
+
Task

Style a complete navigation bar using as many selector types as naturally fit. The nav has a logo, a list of links, and a CTA button. Use element, class, combinator, attribute, and pseudo-class selectors.

  • nav background: dark
  • nav a — base link colour
  • nav a:hover — highlight colour
  • nav ul > li — remove bullet, display inline
  • .btn-cta — different background from links
  • a[href="/contact"] — a distinct accent colour
✓ Success Criteria
  • At least 5 different selector types used
  • Hover state styled on links
  • CTA button visually different from text links
  • No !important anywhere
Chapter 02

The Box Model

Practise the four layers of the box model, the border-box fix, display types, and overflow — the building blocks of every CSS layout.

8 Exercises
EX 01
Add the Universal Box-Sizing Fix
Easy
+
Task

Create a box that is exactly 300px wide with 24px padding and a 2px border. First measure its actual width without box-sizing. Then add the universal fix and confirm it stays at exactly 300px.

✓ Success Criteria
  • Without fix: element is 352px (300 + 48 padding + 4 border)
  • *, *::before, *::after { box-sizing: border-box; } is at the very top of CSS
  • With fix: element stays at exactly 300px total width
EX 02
Padding Shorthand Patterns
Easy
+
Task

Style 4 elements using the 4 padding shorthand patterns. Each must use a different shorthand form and display the resulting spacing visibly with a background colour.

  • 1 value: all sides
  • 2 values: vertical | horizontal
  • 3 values: top | horizontal | bottom
  • 4 values: top | right | bottom | left
✓ Success Criteria
  • All 4 shorthand forms used exactly once
  • Comments above each rule explain the shorthand meaning
  • Visual spacing difference is visible between elements
EX 03
Margin Collapse
Medium
+
Task

Vertical margins between block elements collapse — the larger value wins and they do not add. Demonstrate this, then prevent it using a flexbox wrapper.

  • Create two paragraphs: first with margin-bottom 32px, second with margin-top 16px
  • Observe: the gap between them is 32px, not 48px
  • Wrap them in a flex container to prevent collapse — observe: now 48px
✓ Success Criteria
  • Without flex: gap is 32px (larger margin wins)
  • With display:flex on parent: gap is 48px (both margins apply)
  • Comment explains why this happens
EX 04
Display Types
Medium
+
Task

Create three identical-looking buttons using block, inline, and inline-block elements. Then demonstrate the key difference — block takes full width, inline ignores width/height, inline-block respects both but sits in text flow.

✓ Success Criteria
  • Block button: takes full available width
  • Inline button: ignores width property — stays content-sized
  • Inline-block button: respects width, sits next to text inline
EX 05
Overflow — Clip, Scroll, Auto
Medium
+
Task

Create a fixed-height container with too much content. Apply overflow: hidden, then overflow: auto, then overflow: scroll. Note the visual differences and when each is appropriate.

✓ Success Criteria
  • hidden: content is clipped — no scrollbar
  • auto: scrollbar only when content overflows ✓ preferred
  • scroll: scrollbar always visible even when not needed
EX 06
Build a Profile Card
Medium
+
Task

Build a profile card using only box model properties — no flexbox or grid yet. Control everything with width, padding, margin, border, border-radius, and overflow.

  • Card: 320px wide, padding 24px, rounded corners, dark bg
  • Avatar image: 80×80px circle using border-radius 50% + overflow hidden
  • Spacing between elements using margin only
✓ Success Criteria
  • Card is exactly 320px wide (border-box)
  • Avatar is circular (50% border-radius + overflow: hidden)
  • Consistent spacing using margin
EX 07
Border Styles and Radius
Medium
+
Task

Create 5 boxes demonstrating different border styles (solid, dashed, dotted, double, none) and 4 boxes demonstrating different border-radius values (4px, 16px, 50%, pill shape).

✓ Success Criteria
  • 5 border style boxes, each labelled
  • 50% radius on a square = perfect circle
  • Pill shape: border-radius: 999px on a wide short element
EX 08
Recreate the Box Model Diagram
Challenging
+
Task

Recreate the box model diagram from the course chapter — nested boxes showing margin (outermost), border, padding, and content — using only CSS boxes with different backgrounds and borders. Each layer must be visually distinct with a label.

✓ Success Criteria
  • 4 nested visible layers: margin zone, border, padding zone, content
  • Each layer has a distinct colour scheme
  • Labels identify each layer
  • Demonstrates deep understanding of the box model
Chapter 03

Typography

Practise font stacks, rem sizing, fluid clamp(), line-height, and the text effects used in professional UIs.

8 Exercises
EX 01
Build a Font Stack
Easy
+
Task

Set the body font to a Google Font, with two system font fallbacks and a generic fallback. Also set a different monospace font for code elements with its own fallback stack.

✓ Success Criteria
  • @import loads the Google Font
  • font-family has 4+ values: web font, 2 system fonts, generic
  • code and pre have a separate monospace stack
EX 02
rem vs px Comparison
Easy
+
Task

Create two identical paragraphs — one with font-size in px, one in rem. Then add a rule that changes the root font size to 20px. Observe: the rem paragraph scales, the px paragraph does not.

/* Add this to see the difference */
html { font-size: 20px; }
.px-text { font-size: 16px; }   /* stays 16px */
.rem-text { font-size: 1rem; }   /* becomes 20px */
✓ Success Criteria
  • px text stays fixed when root size changes
  • rem text scales proportionally
  • Comment explains why rem is preferred for accessibility
EX 03
Fluid Headings with clamp()
Medium
+
Task

Set all 6 heading sizes (h1–h6) using clamp() so they scale fluidly between mobile and desktop. Each heading should have a distinct minimum, preferred viewport width value, and maximum.

✓ Success Criteria
  • All 6 headings use clamp(min, preferred, max)
  • h1 is largest (e.g. clamp(28px, 5vw, 64px)), h6 smallest
  • Resize the browser — headings scale smoothly between bounds
EX 04
Line Height and Letter Spacing
Medium
+
Task

Create two text blocks and one heading. Set unitless line-height on the body text (1.7), a tighter line-height on the heading (1.05), and positive letter-spacing on an uppercase label (3px).

✓ Success Criteria
  • Body: unitless line-height 1.5–1.8
  • Heading: tight line-height 1.0–1.2
  • Label: uppercase + letter-spacing: 3px
EX 05
Truncate Long Text
Medium
+
Task

Create a card with a fixed width. Add a long title that overflows. Apply the three-property truncation pattern to show an ellipsis instead.

/* All three required together */
.card-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
✓ Success Criteria
  • All three properties present — none can be omitted
  • Long title shows ... at the end instead of overflowing
  • Card remains its fixed width
EX 06
Gradient Text
Medium
+
Task

Apply a gradient text effect to an h1 heading using the three required properties. The gradient should go from purple (#7c6af7) to cyan (#5af7c0) at a 135deg angle.

✓ Success Criteria
  • background: linear-gradient(...) applied
  • -webkit-background-clip: text and background-clip: text
  • -webkit-text-fill-color: transparent
  • Gradient is visible on the text characters only
EX 07
Text Alignment and Decoration
Medium
+
Task

Create a blog post layout. Left-align body text, centre the article header, right-align a date, and style links with no underline by default but underline on hover.

✓ Success Criteria
  • 3 different text-align values used in context
  • Links: text-decoration: none default, text-decoration: underline on :hover
EX 08
Build a Typography Scale
Challenging
+
Task

Build a complete typography system for a blog. Define a type scale using CSS variables for all sizes, weights, and line-heights. Then apply the system to a realistic page layout: hero, section headings, body paragraphs, labels, captions, and code snippets.

  • At least 6 --type-* CSS variables
  • All heading sizes using clamp()
  • Gradient text on the h1
  • Truncated card titles
  • Monospace font for code
✓ Success Criteria
  • Type scale defined entirely in CSS variables
  • Consistent visual hierarchy across all text elements
  • Headings scale fluidly on browser resize
  • Zero magic numbers — everything references a token
Chapter 04

Flexbox

Practise distributing space, aligning items, wrapping rows, and building common UI patterns using flexbox.

8 Exercises
EX 01
Activate Flexbox
Easy
+
Task

Take a div with 3 child elements. Add display: flex to the parent. Observe how they line up in a row. Add gap: 16px between them. Then change flex-direction to column and observe the change.

✓ Success Criteria
  • Default row direction: children lined up horizontally
  • gap: 16px adds even spacing
  • flex-direction: column: children stack vertically
EX 02
Navigation Bar
Easy
+
Task

Build a navbar with a logo on the left and navigation links on the right. Use justify-content: space-between to push them apart and align-items: center to vertically centre them.

✓ Success Criteria
  • Logo on left, links on right using space-between
  • Items vertically centred using align-items: center
  • nav height is 64px or consistent
EX 03
Centre Anything
Easy
+
Task

Create a full-viewport hero section with a heading and subtitle perfectly centred both horizontally and vertically. Use flexbox.

✓ Success Criteria
  • display:flex + align-items:center + justify-content:center
  • flex-direction: column so heading and subtitle stack vertically
  • min-height: 100vh
EX 04
Flex Grow and Shrink
Medium
+
Task

Create a row of 3 cards. Make the middle card twice as wide as the others using flex-grow. Then make one card fixed at 200px using flex: 0 0 200px.

✓ Success Criteria
  • Cards 1&3: flex: 1 — equal width
  • Card 2: flex: 2 — twice as wide
  • Fixed card: flex: 0 0 200px — never grows or shrinks
EX 05
Responsive Wrapping Card Grid
Medium
+
Task

Create a row of 5 cards that wraps automatically. Each card should be at least 250px wide and grow to fill space. Use flex-wrap: wrap and flex: 1 1 250px.

✓ Success Criteria
  • flex-wrap: wrap on container
  • Cards use flex: 1 1 250px
  • Cards wrap to new lines when the viewport narrows
EX 06
Sidebar Layout
Medium
+
Task

Build a two-column layout with a fixed 260px sidebar and a fluid main content area. The sidebar should never grow or shrink.

✓ Success Criteria
  • Sidebar: flex: 0 0 260px — fixed, immovable
  • Main: flex: 1 — takes all remaining space
  • gap: 32px between columns
EX 07
margin-left: auto Push
Medium
+
Task

In a navbar, push the Sign In and Register buttons to the far right using margin-left: auto on the first button — without changing justify-content. The logo and links stay left, buttons go right.

✓ Success Criteria
  • Logo and links remain on the left
  • Buttons pushed right using margin-left: auto on the first button
  • justify-content is NOT changed — stays flex-start
EX 08
Build a Complete Flexbox Page Layout
Challenging
+
Task

Build a complete page layout using only flexbox: sticky navbar (flex, space-between, align-items), hero (flex, column, center, 100vh), card grid (flex, wrap, gap), and footer (flex, space-between). No grid, no absolute positioning.

✓ Success Criteria
  • 4 distinct layout sections, all using flexbox
  • Navbar, hero, cards, footer each have correct flex behaviour
  • Responsive: cards wrap on small screens
Chapter 05

CSS Grid

Practise two-dimensional layouts — auto-fit card grids, named areas, spanning, and full-page layouts.

8 Exercises
EX 01
Your First Grid
Easy
+
Task

Create a 3-column grid with 4 rows of items. Use display: grid with repeat(3, 1fr) and gap: 16px. Add a background to each cell to see the grid clearly.

✓ Success Criteria
  • display: grid on container
  • grid-template-columns: repeat(3, 1fr)
  • Items fill grid left-to-right automatically
EX 02
Responsive auto-fit Grid
Easy
+
Task

Create a responsive card grid using repeat(auto-fit, minmax(250px, 1fr)). Resize the browser — it should go from 1 column on mobile to 4+ on a wide screen with zero media queries.

✓ Success Criteria
  • Single line: grid-template-columns: repeat(auto-fit, minmax(250px, 1fr))
  • Grid reflows at all widths with no breakpoints
EX 03
Spanning Items
Medium
+
Task

In a 3-column grid, make the first card span all 3 columns (featured hero). Make the second card span 2 columns and 2 rows. Use grid-column: span X and grid-row: span X.

✓ Success Criteria
  • First card: grid-column: 1 / -1 spans full width
  • Second card: grid-column: span 2; grid-row: span 2
  • Other items fill the remaining cells
EX 04
Named Grid Areas
Medium
+
Task

Build a page layout using grid-template-areas. Define header spanning full width, a sidebar and main side by side, and a footer spanning full width.

.page {
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
}
✓ Success Criteria
  • grid-template-areas defined as a text map
  • Each element assigned to its area using grid-area
  • Header and footer span both columns
EX 05
Grid vs Flexbox Decision
Medium
+
Task

Build these two layouts and decide which tool (grid or flexbox) is more natural for each. Write a comment explaining your choice: (A) a row of nav items that wrap on small screens; (B) a dashboard with 4 equal quadrants.

✓ Success Criteria
  • Nav: flexbox — single axis, wrap behaviour
  • Dashboard: grid — two dimensions, precise cell placement
  • Comments justify each choice
EX 06
Mixed Fixed and Fluid Columns
Medium
+
Task

Create a 3-column layout: 200px fixed sidebar, fluid auto main column, 160px fixed right panel. Use grid-template-columns: 200px auto 160px.

✓ Success Criteria
  • Left sidebar stays at 200px on resize
  • Middle column flexes to fill remaining space
  • Right panel stays at 160px
EX 07
Responsive Grid with Media Query
Medium
+
Task

Build a grid that is 1 column on mobile, 2 on tablet (768px+), and 3 on desktop (1200px+). Use grid-template-columns inside media queries.

✓ Success Criteria
  • Mobile base: 1fr (single column)
  • @media 768px: repeat(2, 1fr)
  • @media 1200px: repeat(3, 1fr)
EX 08
Build a Magazine Layout
Challenging
+
Task

Build a 12-column magazine layout. Featured article spans 8 columns, sidebar spans 4. Below: 3 equal article cards span 4 columns each. Use grid-column: X / X for precise placement.

✓ Success Criteria
  • 12-column grid defined
  • Featured: grid-column: 1 / 9 (8 columns)
  • Sidebar: grid-column: 9 / 13 (4 columns)
  • 3 cards: 4 columns each = 4/1, 4/5, 4/9 positions
Chapter 06

Positioning

Practise the five position values through real-world patterns — sticky navbars, badge overlays, centred modals, and tooltips.

8 Exercises
EX 01
relative: The Positioning Context
Easy
+
Task

Add position: relative to a parent div. Then add position: absolute to a child. Move the child to the top-right corner of the parent using top: 0 right: 0. Confirm the child positions relative to parent, not the page.

✓ Success Criteria
  • Parent has position: relative
  • Child has position: absolute; top: 0; right: 0
  • Child sits at the corner of its parent, not the page
EX 02
Product Card with Badge
Easy
+
Task

Build a product card with a "PRO" badge in the top-right corner. The badge must be positioned relative to the card, not the page.

✓ Success Criteria
  • Card has position: relative
  • Badge has position: absolute; top: 12px; right: 12px
  • Badge stays in the card corner when the page scrolls
EX 03
Sticky Navigation
Medium
+
Task

Make a navbar stick to the top of the screen when the user scrolls past it. Add enough page content to make it scrollable. The nav must have a background colour or content will show through.

✓ Success Criteria
  • nav has position: sticky; top: 0
  • Nav has a background colour
  • Nav has z-index: 100 to stay above scrolled content
  • Content below continues scrolling normally
EX 04
Centred Modal Dialog
Medium
+
Task

Build a full-screen overlay backdrop and a centred modal card using position: fixed. Centre the modal using the transform trick.

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
✓ Success Criteria
  • Backdrop: position fixed; inset: 0; background rgba
  • Modal: position fixed; top 50%; left 50%; transform translate(-50%,-50%)
  • Modal z-index higher than backdrop
EX 05
Tooltip on Hover
Medium
+
Task

Create a button that shows a tooltip above it on hover. The tooltip is absolutely positioned relative to the button wrapper. No JavaScript — CSS only.

✓ Success Criteria
  • Tooltip wrapper: position: relative
  • Tooltip: position: absolute; bottom: calc(100% + 8px)
  • Tooltip hidden by default (opacity: 0 or display: none)
  • Tooltip visible on .tooltip-wrap:hover .tooltip
EX 06
Fixed Notification Banner
Medium
+
Task

Create a cookie consent banner fixed to the bottom of the screen. It must stay visible when the user scrolls up the page, and sit above all other content.

✓ Success Criteria
  • position: fixed; bottom: 0; left: 0; right: 0
  • z-index high enough to sit above page content
  • Banner stays at bottom while page scrolls
EX 07
Z-Index Stacking
Medium
+
Task

Create 4 overlapping cards, each with a different z-index. Confirm that higher z-index appears on top. Demonstrate that z-index only works on positioned elements — test it by removing position from one card.

✓ Success Criteria
  • Cards with z-index: 1,2,3,4 — card 4 on top
  • Removing position from a card: z-index has no effect
EX 08
Image Caption Overlay
Challenging
+
Task

Build an image card where hovering reveals a dark gradient overlay with the image title and tags. Use position: absolute to place the overlay, and transition to reveal it on hover.

✓ Success Criteria
  • Card has position: relative; overflow: hidden
  • Overlay: absolute; inset: 0; background gradient; opacity: 0 default
  • Title and tags inside overlay using position: absolute
  • opacity: 1 on .card:hover .overlay via transition
Chapter 07

Responsive Design

Practise mobile-first CSS, media queries, responsive units, and user preference queries.

8 Exercises
EX 01
Mobile-First Base Styles
Easy
+
Task

Write base CSS for a single-column page layout — no media queries yet. Padding 16px, font-size 1rem, single column grid, full-width images. This is your mobile baseline.

✓ Success Criteria
  • Zero media queries — this is the mobile base
  • Everything stacks in one column
  • Images are max-width: 100%
EX 02
Add Tablet and Desktop Breakpoints
Easy
+
Task

Add two min-width media queries to the layout from EX 01. At 768px: 2-column grid, 32px padding. At 1200px: 3-column grid, max-width 1200px centered, 48px padding.

✓ Success Criteria
  • @media (min-width: 768px) — tablet styles
  • @media (min-width: 1200px) — desktop styles
  • Mobile base not modified — only additions
EX 03
Dark Mode with prefers-color-scheme
Medium
+
Task

Build a light-themed page. Add a CSS variables layer and a prefers-color-scheme: dark media query that swaps the colour tokens. No JavaScript — pure CSS dark mode.

✓ Success Criteria
  • Light theme defined in :root
  • @media (prefers-color-scheme: dark) redefines colour tokens
  • All page colours update automatically when OS dark mode is enabled
EX 04
Responsive Units Comparison
Medium
+
Task

Create 5 boxes with widths set using px, %, vw, em, and rem. Resize the browser for each and observe how each unit behaves. Add a comment explaining when each unit is most appropriate.

✓ Success Criteria
  • All 5 unit types demonstrated
  • % responds to parent width, vw to viewport, em to parent font-size, rem to root
  • Comments explain the appropriate use case for each
EX 05
Hide and Show Elements at Breakpoints
Medium
+
Task

Create a mobile hamburger menu icon and a desktop navigation bar. The mobile icon is visible only on small screens; the desktop nav is hidden on small screens.

✓ Success Criteria
  • .mobile-menu-icon: visible by default, display:none at 768px+
  • .desktop-nav: display:none by default, display:flex at 768px+
EX 06
prefers-reduced-motion Override
Medium
+
Task

Add a bouncing animation to a page element. Then add a prefers-reduced-motion media query that sets animation-duration to 0.01ms for users who have enabled reduce motion in their OS settings.

✓ Success Criteria
  • Animation visible by default
  • @media (prefers-reduced-motion: reduce) eliminates the animation
  • Comment explains the accessibility reason
EX 07
Fluid Container with clamp()
Medium
+
Task

Build a container that has proportional horizontal padding at every screen size without any media queries — using padding-inline: clamp(). Min 16px, max 64px, preferred 5vw.

✓ Success Criteria
  • padding-inline: clamp(16px, 5vw, 64px)
  • Zero media queries for padding
  • Padding scales smoothly on resize
EX 08
Fully Responsive Landing Page
Challenging
+
Task

Build a fully responsive landing page from scratch: mobile-first base → tablet 768px → desktop 1200px. Must include: fluid typography with clamp, auto-fit card grid, responsive navbar that switches from stacked to horizontal, dark mode support, and reduced motion override.

✓ Success Criteria
  • Mobile-first approach — additions only, no overrides
  • 2 breakpoints at 768 and 1200px
  • clamp() headings, auto-fit grid, dark mode, reduced motion
sr-only utility class from memory. Then use it on 3 elements: an icon button label, a skip link, and a visually hidden section heading that still appears in the accessibility tree.

✓ Success Criteria
EX 04
Cascade Layers
Medium
+
Task

Define 3 cascade layers: base, components, utilities. Put conflicting colour rules in each. Confirm that utilities always win over components which always win over base — regardless of specificity.

✓ Success Criteria
  • @layer base, components, utilities declared at top
  • Same element targeted in all 3 layers with different colours
  • Utilities colour wins — layer order beats specificity
EX 05
Refactor: Remove All !important
Medium
+
Task

The stylesheet below has 6 !important declarations. Refactor every single one using proper specificity or cascade layers instead.

p         { color: gray !important; }
.hero p   { color: white !important; }
.card     { padding: 24px !important; }
.hidden   { display: none !important; }
nav a     { color: #888 !important; }
nav a:hover{ color: white !important; }
✓ Success Criteria
  • Zero !important declarations remain
  • Same visual output maintained
  • Comments explain the specificity fix for each
EX 06
Build a Button Component with BEM
Medium
+
Task

Build a button component system using BEM. Base .btn block + size modifiers (--sm, --lg) + colour modifiers (--primary, --danger, --ghost) + state element (--loading with spinner).

✓ Success Criteria
  • .btn — base styles
  • .btn--sm and .btn--lg — size modifiers
  • .btn--primary, .btn--danger, .btn--ghost — colour modifiers
  • .btn--loading — shows spinner, disables pointer events
EX 07
Utility Class Library
Medium
+
Task

Build a small utility class library covering: display (flex, grid, hidden), text alignment (text-left, text-center, text-right), margin helpers (mt-1 through mt-4), and the sr-only pattern.

✓ Success Criteria
  • At least 12 utility classes defined
  • Each utility does exactly one thing
  • Utilities placed in @layer utilities so they win over components
EX 08
The Perfect CSS File — Score 100
Challenging
+
Task

Write a production-ready CSS file for a full page — applying every concept from all 12 chapters. Modern reset → design tokens → fluid typography → flexbox nav → grid layout → position badge → responsive breakpoints → hover transitions → entrance animations → dark mode → BEM components → utilities in @layer.

✓ Success Criteria
  • Modern reset at top
  • All values as CSS variable tokens
  • Fluid heading typography with clamp()
  • Flexbox navbar + grid content + positioned badge
  • Mobile-first with 2 breakpoints
  • Transition on all interactive elements
  • @keyframes entrance on page load
  • prefers-color-scheme dark mode
  • prefers-reduced-motion override
  • BEM component naming
  • @layer cascade organisation

Open the Playground — Start Styling

Write your CSS alongside the HTML, switch to the Preview tab to see results instantly, and use the browser DevTools to inspect the box model.

⚡ Open Playground