Skip to content
Codewilds

HTML & CSS cheat sheet

The essential HTML & CSS syntax on one page. Every snippet comes from a lesson of our interactive Learn HTML & CSS course — click "Practise" to write it yourself and get instant feedback.

Last updated on .

HTML Basics

HTML Hello World: Your First Web Page

Write your first web page in HTML — a heading and a paragraph — and watch it appear in the live preview. Start learning HTML for free.

<p>This is a paragraph.</p>
Practise: HTML Hello World: Your First Web Page

HTML Headings and Paragraphs: h1–h6, p, strong and em

Learn HTML headings from h1 to h6, paragraphs and line breaks, and how strong and em mark important and emphasised text. Free interactive lesson.

<h1>Dragon Care Guide</h1>
<h2>Feeding</h2>
<h3>Breakfast</h3>
<h3>Dinner</h3>
<h2>Training</h2>
Practise: HTML Headings and Paragraphs: h1–h6, p, strong and em

HTML Links: The a Tag and href

Learn HTML links — the a tag and href, absolute vs relative URLs, opening a new tab safely with target and rel, and jumping to a section with

<a href="https://developer.mozilla.org">MDN Web Docs</a>
Practise: HTML Links: The a Tag and href

HTML Images: The img Tag, src and alt Text

Add images to a web page with the HTML img tag — src, width and alt text — and learn why good alt text matters for accessibility and SEO.

<img src="/icons/owl.svg" alt="A wise owl">
Practise: HTML Images: The img Tag, src and alt Text

HTML Lists: ul, ol, li and Nested Lists

Learn HTML lists — bulleted lists with ul, numbered lists with ol and list items with li — and how to nest one list inside another.

<ul>
  <li>Sword</li>
  <li>Shield</li>
  <li>Potions</li>
</ul>
Practise: HTML Lists: ul, ol, li and Nested Lists

Page Structure & Forms

Semantic HTML: header, nav, main, section, article and footer

Learn the semantic HTML elements header, nav, main, section, article and footer, and why a meaningful page structure helps accessibility and SEO.

<div class="header">
  <div class="nav">...</div>
</div>
<div class="main">...</div>
Practise: Semantic HTML: header, nav, main, section, article and footer

HTML Tables: table, tr, th, td, thead and caption

Build HTML tables for tabular data — rows with tr, header cells with th, data cells with td — grouped with thead and tbody, plus a caption.

<table>
  <tr>
    <td>Ada</td>
    <td>Mage</td>
  </tr>
  <tr>
    <td>Linus</td>
    <td>Knight</td>
  </tr>
</table>
Practise: HTML Tables: table, tr, th, td, thead and caption

HTML Forms: input, label, select, textarea and button

Build HTML forms with labelled text, email, number and checkbox inputs, select menus, textareas, buttons, placeholders and required fields.

<form action="/signup" method="post">
  <label for="hero">Hero name</label>
  <input type="text" id="hero" name="hero">
  <button type="submit">Join</button>
</form>
Practise: HTML Forms: input, label, select, textarea and button

CSS Basics

CSS Selectors: Element, Class, ID and Group Selectors

Learn what CSS is and how to write CSS rules with element, class, id and group selectors — plus how the cascade decides which style wins.

<head>
  <meta charset="utf-8">
  <title>My page</title>
  <style>
    h1 {
      color: teal;
    }
  </style>
</head>
Practise: CSS Selectors: Element, Class, ID and Group Selectors

CSS Colors and Units: hex, rgb(), px, em, rem and %

Learn CSS colours — named, hex and rgb() — text and background colours, and the CSS units px, em, rem and % for font sizes and widths.

h1 { color: tomato; }            /* a named colour */
h1 { color: #ff6347; }           /* hex */
h1 { color: rgb(255, 99, 71); }  /* rgb() */
Practise: CSS Colors and Units: hex, rgb(), px, em, rem and %

CSS Text and Fonts: font-family, font-size and line-height

Style text with CSS — font-family stacks, font-size, font-weight, line-height, text-align and text-decoration — and make any page easy to read.

body {
  font-family: Georgia, "Times New Roman", serif;
}
code {
  font-family: Consolas, "Courier New", monospace;
}
Practise: CSS Text and Fonts: font-family, font-size and line-height

CSS Box Model: Padding, Border, Margin and box-sizing

Understand the CSS box model — content, padding, border and margin — and how box-sizing border-box makes the width of a box easy to predict.

.card {
  width: 300px;
  padding: 20px;
  border: 2px solid #333;
  margin: 24px;
}
Practise: CSS Box Model: Padding, Border, Margin and box-sizing

Layout with Flexbox

CSS display Property: Block, Inline and Inline-Block

Learn the CSS display property: block vs inline vs inline-block elements, hiding elements with display: none, and why every page layout starts here.

<p>This paragraph is a block. <strong>This is inline</strong> and <a href="#">so is this link</a>.</p>
<p>A second block always starts on a new line.</p>
Practise: CSS display Property: Block, Inline and Inline-Block

CSS Flexbox Basics: Line Up Items in a Row

Learn CSS flexbox: display: flex, flex-direction, justify-content, align-items and gap. Build a row of buttons and a perfectly centred hero section.

<div class="toolbar">
  <button>Save</button>
  <button>Share</button>
  <button>Delete</button>
</div>
Practise: CSS Flexbox Basics: Line Up Items in a Row

CSS flex-wrap and flex-grow: Rows That Wrap and Stretch

Make flexbox rows wrap and share space with flex-wrap, flex-grow, flex-shrink, flex-basis and the flex shorthand. Build a search bar and a card row.

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px; /* used between items and between lines */
}
Practise: CSS flex-wrap and flex-grow: Rows That Wrap and Stretch

Grid & Responsive Design

CSS Grid Tutorial: Columns, fr Units and Gap

Learn CSS Grid layout: display: grid, grid-template-columns with fr units and repeat(), gap, and spanning columns with grid-column. Build a dashboard.

.gallery {
  display: grid;
  grid-template-columns: 200px 200px 200px; /* three columns, 200px each */
}
Practise: CSS Grid Tutorial: Columns, fr Units and Gap

Responsive Web Design: Media Queries and the Viewport

Make pages work on phones and desktops: the viewport meta tag, CSS media queries with max-width and min-width, rem units and centred containers.

<meta name="viewport" content="width=device-width, initial-scale=1">
Practise: Responsive Web Design: Media Queries and the Viewport

Polish & Interaction

CSS Pseudo-Classes: :hover, :focus and :nth-child

Style elements by state and position with CSS pseudo-classes: :hover, :focus, :first-child, :last-child and :nth-child. Build a menu and a striped table.

.btn {
  background: #f5b301;
}
.btn:hover {
  background: #ffc935; /* a little lighter while hovered */
}
Practise: CSS Pseudo-Classes: :hover, :focus and :nth-child

CSS Position: Relative, Absolute, Fixed and Sticky

Learn CSS positioning: relative, absolute, fixed and sticky, with top, right and z-index. Pin a badge to a card's corner and build a sticky header.

.nudge {
  position: relative;
  top: 4px;  /* 4px lower than normal */
  left: 8px; /* 8px further right */
}
Practise: CSS Position: Relative, Absolute, Fixed and Sticky

CSS Variables and Transitions: Smooth Hover Effects

Learn CSS custom properties (--name and var()) and smooth hover effects with transition and transform. Build themeable shop cards that lift on hover.

:root {
  --accent: #f5b301;
  --radius: 12px;
}

.button {
  background: var(--accent);
  border-radius: var(--radius);
}
Practise: CSS Variables and Transitions: Smooth Hover Effects