HTML and CSS Basics
The building blocks every website is made of, including this one.
Last updated: September 23, 2026
Basic structure of an HTML page
Every HTML file follows the same basic structure before any visible content appears.
<!DOCTYPE html>Tells the browser that a current HTML version is being used<html>Wraps the entire page<head>Contains invisible information like the title and linked files<body>Contains the visible content of the pageCommon HTML elements
HTML describes a page's structure using so called tags, usually in pairs of a start and an end.
<h1> to <h6>Headings, h1 the most important, h6 the least<p>A paragraph of text<a href="...">A link to another page<img src="...">Embeds an image, has no separate end tag<div>A generic container with no meaning of its own, only used for grouping<ul> and <li>A list and its individual itemsAttributes
Extra information inside a start tag that describes the element in more detail.
class="..."Assigns a name that CSS or JavaScript can use to target the elementid="..."Like class, but unique, may only appear once per pagesrc="..."Gives the file path for images or scriptsalt="..."Alternative text for an image, important for accessibilityAdding CSS
CSS controls how HTML looks, not what it means.
<link rel="stylesheet" href="style.css">Links an external CSS file in the head, the usual approachstyle="..."CSS directly on an element, only suitable for quick tests<style>...</style>CSS directly in the page's head, without an external fileCSS selectors
Selectors decide which elements a CSS rule applies to.
h1 { }Applies to all h1 elements on the page.card { }Applies to all elements with class="card"#header { }Applies to the one element with id="header"a:hover { }Applies to a link only while the mouse hovers over itCommon CSS properties
Inside the curly braces sit the actual styling rules.
colorText colorbackgroundBackground color or background imagefont-sizeFont sizemarginSpace outside an elementpaddingSpace inside an element, between the border and the contentdisplay: flexArranges child elements side by side, the basis of modern layoutsThe box model
CSS treats every HTML element as a rectangular box, made of four layers from the inside out.
ContentThe actual content, for example the textPaddingInner spacing between the content and the borderBorderThe border itselfMarginOuter spacing to other elements