</>HTML & CSS

Learn HTML & CSS – tutorial, cheatsheet & exercises

HTML and CSS are the foundation of every web page. HTML describes the structure and meaning of content (headings, paragraphs, forms, tables), CSS controls the appearance (colors, spacing, layout, animations). Both are declarative: you describe what is there and how it should look – the browser does the rest.

All you need is an editor and a browser. That makes HTML/CSS the perfect entry into programming – and, for experienced developers, a field with plenty of depth: modern layouts with Flexbox and Grid, responsive design, CSS variables, animations and accessibility. In this course all examples run directly in the browser: click "Run" and change the code.

Web pagesLayoutsEmail templatesResponsive design

Hello World in HTML & CSS

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Hello World</title>
</head>
<body>
  <h1>Hello World!</h1>
  <p>My first web page.</p>
</body>
</html>

The minimum of a page: <!DOCTYPE html> activates standards mode, lang helps screen readers and translators, charset ensures correct umlauts and special characters, and the viewport tag ensures correct display on smartphones.

How to get started with HTML & CSS

You need three things: a text editor (recommended: Visual Studio Code, free – with the "Live Server" extension the browser reloads automatically on every change), a modern browser (Chrome, Firefox, Safari or Edge) and a folder for your project. A web page is initially just a text file with the extension .html.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My Project</title>
  <style>
    body { font-family: system-ui, sans-serif; background: #fff; color: #222; }
    h1 { color: #e34f26; }
  </style>
</head>
<body>
  <h1>It works!</h1>
  <p>Save this file as <code>index.html</code> and open it in the browser with a double click.</p>
</body>
</html>

You organize larger projects in several files: index.html, style.css (included with <link rel="stylesheet" href="style.css">) and optionally script.js. Make sure to save the file as UTF-8 and to set <meta charset="utf-8">, otherwise umlauts and other special characters appear broken.

The most important tools are the browser's developer tools (DevTools): right-click an element → "Inspect", or F12, or Cmd+Option+I (Mac) / Ctrl+Shift+I. In the "Elements" tab you see the DOM and the applied CSS rules, can change values live (colors, spacing, Flexbox properties) and can test the view for smartphones with the device icon.

TipTo try things out without installing anything: online editors such as CodePen, JSFiddle or StackBlitz. To check your code, the W3C Validator (validator.w3.org) and the Lighthouse report in the Chrome DevTools (accessibility, performance) help.

HTML & CSS learning path

Beginner
Intermediate
Advanced

At a glance

First released1993
CreatorTim Berners-Lee / Håkon W. Lie
ParadigmMarkup and stylesheet language (declarative)
Typing–
ExecutionRendered by the browser
File extension.html / .css

Test & practice

Interactive quiz, timed exam with certificate, and exercises with an editor:

HTML & CSS compared

Hello World: HTML & CSS comparedVariables: HTML & CSS comparedConditionals: HTML & CSS comparedLoops: HTML & CSS comparedFunctions: HTML & CSS comparedLists and Arrays: HTML & CSS comparedDictionaries and Maps: HTML & CSS comparedClasses and Objects: HTML & CSS comparedError Handling: HTML & CSS comparedReading Files: HTML & CSS compared