Semantic HTML

Write HTML that describes meaning, not just looks, so browsers, search engines and screen readers understand your pages.

Beginner · about 5 hours · difficulty 1/5

Learn first: HTTP, Requests and Responses

React and Next.js still output HTML. Good HTML makes your app faster, more accessible and easier to style; bad HTML causes bugs no framework can fix.

Structure

  • Document basics: doctype, head (title, meta viewport, description), body.
  • Landmarks: header, nav, main, section, article, aside, footer.
  • Headings h1 to h6 in order, one h1 per page.
  • Lists, tables (for tabular data only), images with meaningful alt text.

Forms are where full-stack starts

Forms send data to your backend. Learn label with for, input types (email, number, date, password), required, name attributes, and how a plain form submits a POST without any JavaScript. Next.js server actions build on exactly this behaviour.

Semantics in practice

Use a button for actions and an anchor for navigation. A div with an onClick is not keyboard accessible and is not announced as a button.

Pitfalls

  • Div soup: everything wrapped in div and span with no meaning.
  • Missing labels on inputs, which breaks screen readers and makes click targets tiny.
  • Using headings to make text bigger instead of to structure content.

You are ready to move on when you can build a placement registration form and a profile page using only semantic HTML that works with the keyboard alone.

Key concepts

  • Document structure and meta tags
  • Landmarks and headings
  • Links, images and alt text
  • Forms, labels and input types
  • Buttons vs links
  • Tables for tabular data
  • Open Graph meta tags

Mini project

Build a static college fest registration page with a semantic layout and a form (name, roll number, email, event choice) that posts to a test endpoint such as httpbin.org/post.

Check yourself

Why is a clickable div worse than a button element, even if both look identical after styling?

Free resources