HTML and CSS Tutorial for Complete Beginners (2026 Edition)
HTML and CSS tutorial for beginners: learn how web pages are structured and styled, with real code examples and a hands-on project to build today.
HTML and CSS are the foundation of every website on the internet โ no exceptions. HTML (HyperText Markup Language) defines the structure and content of a webpage, while CSS (Cascading Style Sheets) controls how that content looks: colors, fonts, layout, spacing, and animations. You can learn enough HTML and CSS to build a real, functional webpage in a single afternoon. This tutorial gives you the complete foundation, step by step, with actual code you can copy and run in your browser right now.
Understanding HTML: The Skeleton of Every Webpage
HTML works through tags โ short labels wrapped in angle brackets that tell the browser what each piece of content is. The tag h1 marks the most important heading. The tag p marks a paragraph. The tag img displays an image. The tag a creates a clickable link. Every HTML document follows the same structure: an html tag wraps everything, head contains invisible metadata (title, fonts, CSS links), and body contains everything visible on the page.
HTML5 โ the current version โ introduced semantic tags that describe the meaning of content, not just its appearance. The header tag wraps the top navigation area. The main tag wraps the primary content. The article tag marks a self-contained piece of content. The footer tag wraps the bottom of the page. Using semantic HTML has two major benefits: it makes your code readable to other developers, and it dramatically improves your site accessibility and SEO performance in Google Search.
- h1 through h6: headings (h1 = most important, h6 = least important)
- p: paragraph text โ use for all body copy
- a href="url": hyperlink โ wraps text or images to make them clickable
- img src="path" alt="description": displays an image
- ul and ol with li items: unordered (bullet) and ordered (numbered) lists
- div and span: generic containers for grouping content
Understanding CSS: The Style Layer That Makes Pages Beautiful
CSS works through selectors and declarations. A selector targets an HTML element, and declarations define how it should look. The rule "p { color: blue; font-size: 16px; }" makes every paragraph text blue and 16 pixels tall. CSS has three ways to apply styles: inline (directly on the element), internal (in a style tag in the head), or external (in a separate .css file linked in the head). External stylesheets are the professional standard โ they keep HTML and CSS cleanly separated and let you style an entire site by editing one file.
The CSS Box Model is the most fundamental concept in web layout. Every HTML element is treated as a rectangular box with four layers: content (the actual text or image), padding (space between content and border), border (the visible outline), and margin (space between this element and neighboring elements). Understanding the box model explains why elements do not line up as expected and how to fix spacing issues. Setting box-sizing: border-box on all elements (which should be your default) makes the box model significantly more intuitive.
Modern CSS Layout: Flexbox and Grid
Before 2015, CSS layout was notoriously difficult โ developers used floats, tables, and clearfix hacks to position elements. Today, two modern layout systems have solved this completely. Flexbox (Flexible Box Layout) is ideal for arranging items in a single direction โ a row of navigation links, a row of product cards, or a centered hero section. Add display: flex to a container and its children immediately become flexible items you can align, distribute, and reorder with simple properties.
CSS Grid is ideal for two-dimensional layouts โ arranging elements in both rows and columns simultaneously. A complete page layout with a header, sidebar, main content area, and footer can be built in under 10 lines of CSS Grid code. Browser support for both Flexbox and CSS Grid is now 97 percent+ globally according to caniuse.com, meaning you can use them confidently on any modern website without workarounds.
Build Your First Real Webpage: Hands-On Project
Create a file called index.html on your Desktop. Start with the doctype declaration: write DOCTYPE html in angle brackets on line 1. Then open an html tag. Inside, add a head section with a title tag containing "My First Website". Then add a body section. Inside the body, add an h1 with your name, a p tag with a short bio, and an unordered list of three of your hobbies. Open the file in your browser (drag it onto the browser window) and you will see your first webpage. It will look plain, but it is real, valid HTML.
- Create a styles.css file and link it in your head with a link tag
- Set body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; }
- Style your h1 with a color and add padding to your body
- Add a background-color to your page โ try #f5f5f5 for a clean off-white
- Open Chrome DevTools (F12) to inspect your elements and experiment live
Chrome DevTools is the most powerful free learning tool for HTML and CSS. Press F12 on any website, click any element, and see exactly what CSS rules apply to it. You can edit values live and see changes instantly โ this is how professional web developers debug and learn.
Responsive Design: Making Your Site Work on Every Device
A website that looks great on desktop but breaks on mobile is an unfinished website. Responsive design is the practice of building websites that automatically adapt to any screen size. CSS media queries are the primary tool: @media (max-width: 768px) targets screens 768 pixels wide or smaller (tablets and phones). Inside the media query, you override styles specifically for small screens โ reducing font sizes, stacking columns vertically, hiding secondary content. The meta viewport tag in your HTML head (name="viewport" content="width=device-width, initial-scale=1") is mandatory for mobile responsiveness and must appear on every page.