Programming and IT
How to learn HTML and CSS from scratch
HTML describes what a page is made of, CSS describes how it looks. They are not programming languages in the strict sense, but no website does without them, and they are a convenient first step into frontend work. You can learn the basics of layout in two or three months if you build real pages from the first week instead of only reading the reference.
In this article
Tools: a browser and an editor#
You need nothing but a browser and a code editor. VS Code with a live preview extension works well. Your main debugging tool is the browser's developer tools (F12): they show the element tree, the styles applied to each element and the size of every box. Get used to opening them whenever something on the screen looks odd.
A minimal document looks like this:
My first page
Hello
This is a paragraph with a link.
Step 1: semantic HTML (2–3 weeks)#
Headings h1–h6, paragraphs, lists, links, images with an alt attribute,
tables, forms with a label for every field. Then the meaningful containers:
header, nav, main, article, section, footer. The rule: you choose a
tag by what the content means, not by how the tag looks by default. A button is
a button, not a div with a click handler: it can be pressed from the
keyboard, and screen readers understand it.
Check your markup with the W3C validator — it points out unclosed tags and nesting errors.
Step 2: CSS basics (3–4 weeks)#
Selectors (by tag, class, id, attribute, pseudo-classes like :hover), the
cascade and specificity, inheritance. The box model: content, padding,
border, margin, and the box-sizing property. Units: px, rem, %,
vw. Colours, fonts, backgrounds. Most "why did this box end up over there"
questions are answered by the box model, so learn it thoroughly.
Step 3: layout with Flexbox and Grid (3–4 weeks)#
Flexbox lines elements up in a row or a column: menus, cards in a row, centring. Grid handles two-dimensional layouts: the page structure, a gallery. Practise by rebuilding interfaces of sites you know: a header with a menu, a grid of product cards, a footer with several columns.
}
Step 4: responsive design and accessibility#
Media queries with @media, the mobile-first approach, flexible images. Check
your page at 320 pixels wide: nothing should stick out past the edge.
Accessibility means text contrast, a visible focus outline, a sensible heading
order and labels on form fields. The audit built into the browser (Lighthouse
in Chrome, for example) points out the main problems.
A layout portfolio#
Three or four pages built from designs: a one-page landing, an online shop page with a product grid, a sign-up form, a responsive blog. Free practice designs are easy to find — Frontend Mentor publishes them together with briefs. Put each piece in its own repository and publish it on a free static hosting such as GitHub Pages.
How to tell your layout is right#
- Compare the page with the design by laying a screenshot over it: differences in spacing show up immediately.
- Go through the page with the keyboard only — press Tab to reach every link and button.
- Run the HTML through the validator and the CSS through a linter.
- Open the page in two different browsers and on a phone.
Step-by-step plan
- Weeks 1–3 — HTMLDocument structure, text, links, images, tables, forms, semantic tags.
- Weeks 4–7 — CSS basicsSelectors, specificity, the box model, units, fonts and colours.
- Weeks 8–11 — Flexbox and GridRebuild layouts you know: a menu, cards, a footer.
- Weeks 12–13 — responsive design and accessibilityMedia queries, mobile version, contrast, focus, a page audit.
- PortfolioThree or four pages built from designs, each in a repository with a published version.
Start learning this in your own space
The plan goes into your repository: tick off stages, keep notes — the change history shows how far you have come.
Check yourself
1.Which HTML tag creates a link?
2.A box has width: 100px, padding: 10px and border: 2px on all sides, with the default box-sizing (content-box). What is its full width on screen in pixels, not counting margin?
3.Which of these selectors has the highest specificity?
Sources
-
MDN Web DocsReference and learning material for HTML and CSSfree
-
W3C Markup ValidatorChecks HTML markup for errorsfree
-
freeCodeCamp — Responsive Web DesignA free interactive curriculum with projectsfree
-
Frontend MentorPractice designs to build; many are freefree
Was this helpful?