Skip to content
Justice Tech School

CSS Exercises

Fill in the blanks to check your knowledge. Each exercise belongs to a lesson.

CSS Introduction

Exercise

Make all paragraphs blue.

p {
  : blue;
}

CSS Syntax

Exercise

Finish the declaration with the right punctuation.

p {
  color: teal
}

Adding CSS to a Page

Exercise

Add an inline style that makes this text red.

<p ="color: red;">Hello</p>

CSS Comments

Exercise

Finish the comment so the rule below still works.

/* Page title 
h1 { color: navy; }

How To Add CSS

Exercise

Attach an external file.

<link rel="stylesheet" ="style.css">

Rules, Selectors and Declarations

Exercise

Name the part before the braces.

The  picks elements

Absolute and Relative Units

Exercise

Root relative unit.

font-size: 1.5;

Values: Keywords, Numbers and Functions

Exercise

Math function.

width: (100% - 20px);

Shorthand Properties

Exercise

Order of sides.

margin: top  bottom left

Why CSS Does Not Apply

Exercise

Which wins, p.note or .note?

 selector

Basic Selectors

Exercise

Select every element that has class "note".

note {
  color: red;
}

Universal and Grouping Selectors

Exercise

Style h1 and h2 together by separating them with a comma.

h1 h2 {
  color: green;
}

Combinators

Exercise

Select only direct children of .menu that are li.

.menu  li {
  color: blue;
}

Pseudo-classes

Exercise

Style every even list item.

li:nth-child() {
  background: #eee;
}

Pseudo-elements

Exercise

Add generated content before each link.

a:: {
  content: "> ";
}

Attribute Selectors

Exercise

Select inputs whose type is "email".

input[type=] {
  border: 1px solid blue;
}

Specificity and the Cascade

Exercise

Which selector below would win? Fill in the winning kind: a class selector starts with ___ .

note { color: red; }

Inheritance

Exercise

Make the span take its parent colour.

span {
  color: ;
}

Class and ID Selectors

Exercise

Symbol for an ID selector.

hero { color: red }

Element Selectors and Selector Lists

Exercise

Separate selectors with a ___

h1 h2 { color: red }

Descendant and Child Selectors

Exercise

Direct child symbol.

.menu  li

Sibling Selectors

Exercise

Next sibling symbol.

h3  p

Attribute Selectors in Depth

Exercise

Starts with.

a[href="https"]

First, Last and nth Child

Exercise

Odd items.

li:nth-child()

Form State Pseudo Classes

Exercise

When invalid.

input: { border-color: red }

::before and ::after

Exercise

Property needed.

: "*";

::first-line, ::first-letter and ::selection

Exercise

Drop cap.

p::first-

Colours

Exercise

Set the background colour.

body {
  : lightyellow;
}

Backgrounds

Exercise

Use the background property to set a plain colour.

.card {
  : #eee;
}

Background Images

Exercise

Stop the background image from tiling.

.hero {
  background-repeat: ;
}

Gradients

Exercise

Create a gradient that goes to the right.

.bar {
  background: linear-gradient(to , red, blue);
}

Colour Formats

Exercise

HSL stands for hue, saturation and ___

hue, saturation, 

Opacity versus Transparent Colours

Exercise

Fade only the colour.

background: (0 0 0 / .5)

Background Position, Size and Repeat

Exercise

Fill the box, cropping if needed.

background-size: ;

Multiple Backgrounds

Exercise

Layer separator.

background: a b

Linear, Radial and Conic Gradients

Exercise

Gradient around a point.

background: -gradient(red, blue)

The Box Model

Exercise

Add space inside the border.

.card {
  : 20px;
}

Borders

Exercise

Give the box a 2px solid black border.

.box {
  border: 2px  black;
}

Rounded Corners

Exercise

Turn the square into a circle.

.avatar {
  width: 80px;
  height: 80px;
  border-radius: ;
}

Margins

Exercise

Centre this fixed-width block horizontally.

.page {
  width: 600px;
  margin: 0 ;
}

Padding

Exercise

Give the button 10px vertical and 20px horizontal padding.

button {
  padding: ;
}

Width and Height

Exercise

Never let the box grow past 500px.

.box {
  : 500px;
}

Box Sizing

Exercise

Make width include padding and border.

* {
  box-sizing: ;
}

Outlines

Exercise

Add a 2px solid blue outline on focus.

input:focus {
  outline: 2px  blue;
}

Margin Collapse and Auto Margins

Exercise

Centre a block horizontally.

margin: 0 ;

Padding versus Margin

Exercise

Space inside the border.

: 10px;

Border Styles and Individual Sides

Exercise

Dashed style.

border: 2px  red;

Rounded Corners in Depth

Exercise

Make a circle.

border-radius: %;

Box Shadow

Exercise

Shadow inside the box.

box-shadow:  0 0 8px black;

display, visibility and hidden

Exercise

Keep the space.

: hidden;

min and max Width and Height

Exercise

Limit the width.

-width: 600px;

Fonts

Exercise

Make the text bold.

h2 {
  font-: bold;
}

Text Styling

Exercise

Centre the heading text.

h1 {
  text-: center;
}

Spacing and Shadows

Exercise

Set the line height to 1.6 times the font size.

p {
  : 1.6;
}

CSS Units

Exercise

Set the width to 80% of the viewport width.

.hero {
  width: 80;
}

Font Families and Web Fonts

Exercise

Last fallback.

font-family: Arial, ;

Font Weight, Style and Variant

Exercise

Bold with numbers.

font-weight: ;

Text Alignment and Decoration

Exercise

Capitalise every letter.

text-transform: ;

Line Height, Letter and Word Spacing

Exercise

Space between lines.

-height: 1.5;

Text Overflow and Wrapping

Exercise

Show three dots.

text-overflow: ;

Text Shadow and Writing Mode

Exercise

Shadow for text.

-shadow: 1px 1px 2px red;

Icons

Exercise

Make the SVG take the text colour.

svg {
  fill: ;
}

Styling Links

Exercise

Underline the link only when hovered.

a:hover {
  text-decoration: ;
}

Styling Lists

Exercise

Remove the bullets from the list.

ul {
  list-style-type: ;
}

Styling Tables

Exercise

Merge the double borders into single lines.

table {
  border-: collapse;
}

Styling Links and Buttons

Exercise

Mouse over state.

a:

Custom List Markers

Exercise

Style the bullet.

li:: { color: red }

Table Layout with CSS

Exercise

Equal column widths.

table-layout: ;

Display and Visibility

Exercise

Hide the element and remove its space.

.hidden {
  display: ;
}

Position and z-index

Exercise

Position the badge relative to its nearest positioned parent.

.badge {
  position: ;
  top: 0;
  right: 0;
}

Overflow

Exercise

Add scrollbars only when content overflows.

.panel {
  overflow: ;
}

Float and Clear

Exercise

Place the box on the right with text wrapping around it.

.pic {
  : right;
}

Centering Things

Exercise

Centre the child both ways in a grid.

.stage {
  display: grid;
  place-items: ;
}

Block, Inline and Inline-block

Exercise

Accepts width but flows inline.

display: -block;

Static, Relative, Absolute and Fixed

Exercise

Anchor for absolute children.

position: ;

z-index and Stacking

Exercise

Bring to the front.

z-index: ;

Overflow, Scroll and Resize

Exercise

Scrollbars only if needed.

overflow: ;

Float and Clear

Exercise

Float to the right.

float: ;

Centering Cheat Sheet

Exercise

Centre in grid.

place-items: ;

Flexbox Basics

Exercise

Turn the container into a flex container.

.row {
  display: ;
}

Flex Container Properties

Exercise

Stack the flex items vertically.

.menu {
  display: flex;
  flex-direction: ;
}

Flex Item Properties

Exercise

Make the item grow to fill the free space.

.main {
  flex: ;
}

Flex Direction and Wrap

Exercise

Allow new lines.

flex-wrap: ;

justify-content and align-items

Exercise

Even space between items.

justify-content: space-;

flex-grow, flex-shrink and flex-basis

Exercise

Fill free space.

flex: ;

Order, Gap and align-self

Exercise

Move to the start.

order: ;

Flexbox: Navbar and Cards

Exercise

Wrap cards.

flex-wrap: ;

Grid Basics

Exercise

Create three equal columns.

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1);
}

Grid Areas and Placement

Exercise

Make the item span two columns.

.wide {
  grid-column:  2;
}

Responsive Grids

Exercise

Each column must be at least 200px wide.

.g {
  grid-template-columns: repeat(auto-fit, (200px, 1fr));
}

Grid Template Areas

Exercise

Place an item in an area.

-area: header;

Grid Tracks, fr and minmax

Exercise

Three equal columns.

grid-template-columns: (3, 1fr);

Grid Lines and Spanning

Exercise

Span two columns.

grid-column: span ;

Grid Alignment

Exercise

Align items inside cells.

-items: center;

Auto Placement and Dense Packing

Exercise

Fill gaps.

grid-auto-flow: ;

Opacity and Box Shadow

Exercise

Make the element half see-through.

.ghost {
  : 0.5;
}

Hover and Transitions

Exercise

Style the button when the mouse is over it.

button: {
  background: orange;
}

2D Transforms

Exercise

Rotate the box by 45 degrees.

.box {
  transform: (45deg);
}

Animations

Exercise

Define a set of animation stages.

@ fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

Transitions in Depth

Exercise

Animation time.

transition: all  ease;

2D and 3D Transforms

Exercise

Rotate.

transform: (10deg);

Keyframe Animations

Exercise

Repeat forever.

animation-iteration-count: ;

CSS Filters

Exercise

Black and white.

filter: (1);

Cursor, Pointer Events and User Select

Exercise

Hand cursor.

cursor: ;

Navigation Bars

Premium exercise. See plans

Dropdown Menus

Premium exercise. See plans

Image Gallery

Premium exercise. See plans

Styling Forms

Premium exercise. See plans

Responsive Design and Media Queries

Exercise

Apply the style only on screens at least 600px wide.

@ (min-width: 600px) {
  body { font-size: 20px; }
}

Responsive Images and object-fit

Exercise

Crop the image so it fills the box.

img {
  object-fit: ;
}

Media Queries

Exercise

Narrow screens.

@media (max-: 500px)

Mobile First Strategy

Exercise

Wider than 500px.

@media (-width: 500px)

Viewport Units and Fluid Layout

Exercise

Viewport height unit.

height: 50;

Responsive Navigation Pattern

Exercise

Row from 500px up.

flex-direction: ;

Responsive Backgrounds and Images

Exercise

Never overflow the parent.

max-width: %;

CSS and Accessibility

Exercise

Keyboard focus style.

:focus-

Custom Properties (Variables)

Premium exercise. See plans

calc(), min(), max() and clamp()

Premium exercise. See plans

CSS Counters

Premium exercise. See plans

Dark Mode

Premium exercise. See plans

CSS Best Practices

Premium exercise. See plans

Project: Responsive Navbar

Exercise

Space the items out.

justify-content: space-;

Project: Card Grid

Exercise

Auto columns.

repeat(auto-, minmax(90px, 1fr))

Project: Landing Page Styles

Exercise

Read a variable.

background: (--accent);

Project: Dark and Light Theme

Exercise

Dark preference query.

@media (prefers-color-scheme: )

Container Queries

Premium exercise. See plans

The :has() Selector

Premium exercise. See plans

Selector Lists: :is(), :where() and :not()

Premium exercise. See plans

Cascade Layers

Premium exercise. See plans

Native CSS Nesting

Premium exercise. See plans

Subgrid

Premium exercise. See plans

Scroll Snap

Premium exercise. See plans

aspect-ratio and object-fit

Premium exercise. See plans

Logical Properties

Premium exercise. See plans

clip-path and Masks

Premium exercise. See plans

Filters and Blend Modes

Premium exercise. See plans

Modern Colour Functions

Premium exercise. See plans

@property: Typed Variables

Premium exercise. See plans

Sticky Positioning

Premium exercise. See plans

Columns and Gap Utilities

Premium exercise. See plans

Naming and Architecture: BEM

Premium exercise. See plans

Resets and Sensible Defaults

Premium exercise. See plans

Fluid Typography and Spacing

Premium exercise. See plans

Respecting Reduced Motion

Premium exercise. See plans

Rendering Performance

Premium exercise. See plans

Debugging CSS

Premium exercise. See plans

Project: Pricing Cards

Premium exercise. See plans

Project: Hero Section

Premium exercise. See plans

CSS Review Checklist

Premium exercise. See plans