# 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.

## 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:

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first page</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Hello</h1>
  <p>This is a paragraph with a <a href="https://developer.mozilla.org/">link</a>.</p>
</body>
</html>
```

## 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.

```css
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
```

## 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

1. **Weeks 1–3 — HTML** — Document structure, text, links, images, tables, forms, semantic tags.
2. **Weeks 4–7 — CSS basics** — Selectors, specificity, the box model, units, fonts and colours.
3. **Weeks 8–11 — Flexbox and Grid** — Rebuild layouts you know: a menu, cards, a footer.
4. **Weeks 12–13 — responsive design and accessibility** — Media queries, mobile version, contrast, focus, a page audit.
5. **Portfolio** — Three or four pages built from designs, each in a repository with a published version.

## Check yourself

1. Which HTML tag creates a link?
   - <a>
   - <link>
   - <href>
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?
   - div
   - .menu
   - #menu

## Sources

- [MDN Web Docs](https://developer.mozilla.org/) — Reference and learning material for HTML and CSS
- [W3C Markup Validator](https://validator.w3.org/) — Checks HTML markup for errors
- [freeCodeCamp — Responsive Web Design](https://www.freecodecamp.org/learn/) — A free interactive curriculum with projects
- [Frontend Mentor](https://www.frontendmentor.io/) — Practice designs to build; many are free

---

https://skillok.org/articles/en/learn-html-and-css-from-scratch
