HTML and CSS — Web Page Structure, Styling, and Responsive Design

HTML & CSS: Building What People See

Every Website You Have Ever Visited Is Built From Two Things

Every webpage you have ever visited is built from two things: HTML says what is on the page (a heading, a paragraph, an image, a button). CSS says what it looks like (blue text, 20px font, centered, with a shadow). That is it. No matter how complex a website looks -- Apple.com, Reddit, YouTube -- it is HTML elements styled with CSS. You can learn to build a professional-looking webpage in an afternoon. Making it great takes longer, but the barrier to entry is lower than any other technical skill in computing.

Right now, on this page, every word you are reading is wrapped in an HTML tag. The font, the spacing, the colors, the layout that shifts when you resize your browser -- all CSS. The browser you are using is a rendering engine: it reads HTML to know what to display and reads CSS to know how to display it. That is the entire contract. Two languages, one visible result. No server needed, no database, no programming logic. Just structure and style.

This simplicity is why HTML and CSS are the universal entry point into technology. Before you learn JavaScript, before you touch a framework, before you deploy anything -- you need to understand the two languages that every browser on every device on Earth already knows how to read.

95%+
Of all websites use HTML and CSS as their visual foundation
1991
Year Tim Berners-Lee published the first HTML page
142
HTML elements in the current spec -- you use about 20 regularly
500+
CSS properties available, though 30-40 cover most real-world needs

HTML: The Skeleton of Every Page

HTML stands for HyperText Markup Language. It is not a programming language -- it has no logic, no loops, no conditions. It is a markup language: you mark up content to tell the browser what each piece of content is. A heading, a paragraph, a link, an image, a list, a table. The browser reads those marks and renders them on screen.

The fundamental unit of HTML is the element. An element consists of an opening tag, content, and a closing tag. Here is a paragraph element:

<p>This is a paragraph of text.</p>

The <p> is the opening tag. The </p> is the closing tag. Everything between them is the content. That is the pattern for almost every HTML element. Tags can also have attributes -- extra information that modifies the element's behavior. A link needs to know where to go:

<a href="https://hozaki.com">Visit Hozaki</a>

The href attribute tells the browser the destination URL. An image needs to know which file to display:

<img src="photo.jpg" alt="A description of the photo">

Notice that <img> has no closing tag -- it is a self-closing element because it has no text content inside it. The alt attribute provides a text description used by screen readers for visually impaired users, and displayed when the image fails to load.

The Elements You Will Actually Use

HTML has 142 elements in the current specification. In practice, you will use about 20 of them for 95% of everything you build. Here are the ones that matter.

Structure: <html>, <head>, <body> wrap the entire document. <div> is a generic container for grouping elements. <span> is an inline container for styling a portion of text.

Content: <h1> through <h6> for headings (h1 is the largest, h6 the smallest). <p> for paragraphs. <a> for links. <img> for images. <ul> and <ol> for unordered and ordered lists. <li> for list items.

Forms: <form>, <input>, <button>, <textarea>, <select>. These handle user input -- login forms, search bars, comment boxes.

Semantic HTML: Why Tag Choice Matters

You could build an entire website using only <div> tags. It would work. But it would be the HTML equivalent of writing an essay where every sentence is the same font, same size, with no headings, no paragraphs, no structure. Technically readable. Practically useless.

Semantic elements tell the browser -- and screen readers, search engines, and other machines -- what each section of your page means. Instead of a generic <div>, you use <nav> for navigation, <article> for a self-contained piece of content, <aside> for supplementary content, <header> for introductory content, and <footer> for closing content.

Non-Semantic (Works, But Meaningless)
<div class="top">
  <div class="links">...</div>
</div>
<div class="main">
  <div class="post">...</div>
</div>
<div class="bottom">...</div>

Search engines and screen readers see a pile of identical containers. No structure, no meaning, no hierarchy.

Semantic (Same Layout, Rich Meaning)
<header>
  <nav>...</nav>
</header>
<main>
  <article>...</article>
</main>
<footer>...</footer>

Screen readers can jump directly to the nav or main content. Google understands your page structure. Accessibility improves dramatically.

Key Insight

Semantic HTML is not about aesthetics -- a <nav> looks identical to a <div> by default. It is about meaning. Search engines rank semantically correct pages higher. Screen readers navigate them faster. Your future self understands the code immediately. Using the right element for the right purpose is one of the simplest things you can do that has outsized impact.

CSS: The Skin That Changes Everything

HTML without CSS looks like a college essay from 1995 -- Times New Roman, blue underlined links, everything stacked in a single column. CSS transforms that raw structure into something people actually want to look at. The same HTML can look like a sleek tech startup page, a cozy blog, or a neon-drenched gaming site. CSS controls every visual property: colors, fonts, spacing, borders, shadows, animations, layout, and responsiveness.

CSS stands for Cascading Style Sheets. The "cascading" part is important and we will get to it. First, the basics.

A CSS rule has three parts: a selector (what to style), a property (which aspect to change), and a value (what to change it to).

h1 {
  color: #1e3a5f;
  font-size: 36px;
  margin-bottom: 16px;
}

This rule says: find every <h1> element, make its text color dark navy, set its font size to 36 pixels, and add 16 pixels of space below it. That is the entire pattern. Selector, property, value. Every CSS rule follows this structure.

Selectors can target elements by tag name (p), by class (.highlight), by ID (#main-title), or by combinations. Classes are the workhorse of CSS -- you add a class to an HTML element and then style that class:

<p class="intro">Welcome to our site.</p>

.intro {
  font-size: 20px;
  color: #334155;
  line-height: 1.7;
}

The Box Model: How Every Element Occupies Space

Every single element on a webpage is a rectangular box. It does not matter if it looks like a circle, a card with rounded corners, or a button with a shadow. To the browser, it is a box. Understanding how those boxes are sized and spaced is the single most important concept in CSS.

Every box has four layers, from inside to outside: content (the text or image itself), padding (space between the content and the border), border (a visible or invisible edge), and margin (space between this element and neighboring elements).

The CSS Box Model margin margin-bottom: 24px margin-top: 24px border border: 2px solid #1e3a5f padding padding: 20px Content width: 260px height: 90px margin bdr pad content: 260px
The CSS box model. Every HTML element is wrapped in four layers: content (the actual text or image), padding (inner spacing), border (the edge), and margin (outer spacing). When you set width: 260px, you are setting only the content width by default. Padding, border, and margin add to the total space the element occupies.

Here is the gotcha that trips up every beginner. If you set width: 260px and then add padding: 20px and border: 2px, the total width of the element is not 260px. It is 260 + 20 + 20 + 2 + 2 = 304px. The padding and border are added on top of the content width.

This was universally hated. So CSS introduced box-sizing: border-box, which changes the math: when you set width: 260px, the padding and border are included within that 260px. The content area shrinks to accommodate them. Every modern CSS reset starts with this rule:

*, *::before, *::after {
  box-sizing: border-box;
}

If you remember one CSS rule from this entire page, make it that one.

Flexbox: Layouts That Finally Make Sense

For the first 15 years of CSS, layout was a nightmare. Developers used floats, clearfixes, absolute positioning, and inline-block hacks to achieve layouts that should have been simple. Centering an element vertically was a running joke in the industry. Then in 2012, Flexbox arrived and fixed everything.

Flexbox is a one-dimensional layout system. You declare a container as a flex container, and its children automatically arrange themselves in a row or column. You control how they align, how they distribute space, and how they wrap when the container gets too small.

.container {
  display: flex;
  justify-content: center;     /* horizontal alignment */
  align-items: center;         /* vertical alignment */
  gap: 16px;                   /* space between items */
}

Those four lines do what used to require 20 lines of hacky CSS. The justify-content property controls alignment along the main axis (horizontal by default). The align-items property controls alignment along the cross axis (vertical by default). The gap property adds uniform spacing between items without needing margin on each child.

Flexbox Alignment: justify-content and align-items justify-content (main axis) flex-start center space-between space-around flex-end space-evenly align-items (cross axis) flex-start center flex-end stretch Vertical centering in CSS: display: flex; align-items: center; -- the 15-year problem, solved.
Flexbox alignment visualized. The justify-content property distributes items along the main axis (horizontal in a row). The align-items property positions items along the cross axis (vertical in a row). Combining the two gives you complete control over how children are positioned within a flex container.
Real-World Example

The navigation bar on almost every modern website is a flex container. The logo sits on the left (flex-start), the nav links sit on the right (margin-left: auto or justify-content: space-between), and everything is vertically centered (align-items: center). Three CSS properties replace what used to require floats, clearfixes, and line-height hacks. Every navigation bar you see on the web in 2026 almost certainly uses flexbox.

CSS Grid: Two-Dimensional Layouts

Flexbox handles rows or columns -- one dimension at a time. When you need to control rows and columns simultaneously, CSS Grid is the tool. It was designed for full page layouts: header spanning the top, sidebar on the left, main content in the center, footer across the bottom.

.page {
  display: grid;
  grid-template-areas:
    "header  header"
    "sidebar main"
    "footer  footer";
  grid-template-columns: 250px 1fr;
  grid-template-rows: 80px 1fr 60px;
  min-height: 100vh;
}

.header  { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main    { grid-area: main; }
.footer  { grid-area: footer; }

Eight lines of CSS to define a complete page layout. The grid-template-areas property is essentially an ASCII art map of your page. The 1fr unit means "one fraction of the remaining space" -- it is CSS Grid's way of saying "take whatever is left." The named grid areas let you assign elements to positions by name rather than calculating column and row numbers.

When to use flexbox versus grid: use flexbox for components (a nav bar, a card row, a button group). Use grid for layouts (the overall page structure, a dashboard with multiple panels, an image gallery with specific row and column sizing). Most modern pages use both -- grid for the macro layout, flexbox for the micro arrangements within each grid cell.

Responsive Design: One Page, Every Screen Size

In 2016, mobile traffic surpassed desktop traffic globally. Today, over 60% of web traffic comes from phones and tablets. A website that only looks good at 1440px wide is a website that fails for the majority of its visitors. Responsive design is the practice of building pages that adapt to any screen size -- from a 320px phone to a 2560px ultrawide monitor.

The tool is the media query. A media query applies CSS rules only when certain conditions are met -- typically screen width.

/* Base styles: mobile first */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* Tablet: 768px and wider */
@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Desktop: 1200px and wider */
@media (min-width: 1200px) {
  .card-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

On a phone, cards stack in a single column. On a tablet, they sit two across. On a desktop, three across. The content is identical -- only the layout changes. This is mobile-first design: start with the simplest layout (mobile), then add complexity for larger screens. It is the industry standard because it forces you to prioritize content over decoration.

Responsive Breakpoints: Same Content, Three Layouts Mobile (320px) Card 1 Card 2 Card 3 Card 4 1 column Tablet (768px) Card 1 Card 2 Card 3 Card 4 2 columns Desktop (1200px) Card 1 Card 2 Card 3 Card 4 3 columns
The same four cards at three breakpoints. On mobile, everything stacks vertically for easy thumb scrolling. On tablet, two columns use the wider screen. On desktop, three columns fill the available space. The HTML is identical across all three -- only the CSS grid-template-columns value changes at each media query breakpoint.

Real-World CSS: Frameworks, Tailwind, and Bootstrap

Writing every CSS rule from scratch for a production website is like building furniture from raw lumber when IKEA exists. CSS frameworks give you pre-built components and utility classes so you can move faster without reinventing standard patterns.

Tailwind CSS is the dominant approach in 2026. Instead of writing CSS in a separate file, you apply small utility classes directly in your HTML:

<button class="bg-blue-500 text-white px-4 py-2 rounded-lg
               hover:bg-blue-600 transition-colors">
  Sign Up
</button>

Each class does one thing: bg-blue-500 sets a blue background, px-4 adds horizontal padding, rounded-lg adds border radius. It feels verbose at first, but there is a reason GitHub Copilot, OpenAI, Shopify, and Netflix use it: you never leave your HTML file, you never fight CSS specificity wars, and you never write CSS that nobody maintains. Every style is visible right where it is used.

Bootstrap takes a different approach: pre-built components. A card, a modal, a navbar, a dropdown -- all styled and functional out of the box. Add a class like class="btn btn-primary" and you get a fully styled button with hover states and focus rings. Bootstrap is faster for prototyping and ideal when visual originality is less important than speed.

Tailwind CSS (Utility-First)

Philosophy: Compose styles from small, single-purpose classes. Full control over every pixel. No pre-designed components -- you build your own.

Best for: Custom designs, design systems, teams that want total control. Used by GitHub Copilot, OpenAI, Shopify.

Trade-off: Longer class strings in HTML. Requires learning the utility naming conventions.

Bootstrap (Component-Based)

Philosophy: Pre-built, tested components you drop into your page. Consistent look with minimal effort.

Best for: Rapid prototyping, admin dashboards, projects where speed matters more than uniqueness. Used by millions of sites since 2011.

Trade-off: Sites tend to look similar ("Bootstrap look"). Overriding default styles can fight the framework.

For learning, start with vanilla CSS. Understand how properties work, how the box model behaves, how flexbox and grid arrange elements. Then move to a framework when you are building something real. You need to understand what the framework is doing under the hood, or you will be helpless when something breaks.

From Default Browser Styling to Professional Design

The gap between "I know CSS" and "my pages look professional" is not about knowing more properties. It is about understanding four design principles that have nothing to do with code.

Typography: the most underrated skill

Ninety-five percent of web content is text. Typography is not about picking a "cool font." It is about readability, hierarchy, and rhythm. Use no more than two typefaces per page -- one for headings, one for body text. Set body text between 16px and 18px (smaller is harder to read on screens than paper). Set line-height between 1.5 and 1.7 for body text. Use font-weight and size to create clear hierarchy: the reader should instantly know what is a heading, what is a subheading, and what is body text without reading a single word.

Whitespace: the most underrated design tool

Amateur pages cram elements together. Professional pages breathe. Whitespace (the empty space between and around elements) is not "wasted space" -- it is what makes content scannable. Increase padding. Increase margin. Let sections breathe. Apple's website is the canonical example: the product is surrounded by vast emptiness, which forces your eye exactly where they want it.

Color: less is more

Pick one primary color for interactive elements (buttons, links, highlights). Pick one neutral palette for text and backgrounds (typically grays). Add one accent color sparingly for warnings, success states, or emphasis. That is it. Three color roles. More than that and the page looks like a circus.

Consistency: the invisible principle

If your buttons have 8px border radius, all buttons should have 8px border radius. If your section spacing is 64px, all sections should use 64px. If your primary color is #3b82f6, it should be the same blue everywhere. CSS custom properties make this trivial:

:root {
  --color-primary: #3b82f6;
  --radius: 8px;
  --spacing-section: 64px;
}

.button {
  background: var(--color-primary);
  border-radius: var(--radius);
}

section {
  margin-bottom: var(--spacing-section);
}

Change the variable once, the entire site updates. This is also how dark mode works: swap the color variables based on a class or media query, and every element that references them changes simultaneously.

Key Insight

The difference between amateur and professional web design is not CSS knowledge -- it is design discipline. Consistent spacing, deliberate typography, restrained color, and generous whitespace will make a page with 20 lines of CSS look better than a page with 2,000 lines of CSS that ignores these principles. CSS Zen Garden proved this years ago: same HTML, hundreds of completely different designs. The CSS was different. The design principles were the same.

How Dark Mode Actually Works

Dark mode is not a separate website. It is the same HTML and CSS with different color values. The mechanism is CSS custom properties combined with either a CSS class toggle or a media query.

:root {
  --bg: #ffffff;
  --text: #1e293b;
  --card-bg: #f8fafc;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --text: #e2e8f0;
  --card-bg: #1e293b;
}

body {
  background: var(--bg);
  color: var(--text);
}

When a user clicks the dark mode toggle, JavaScript adds data-theme="dark" to the root element. Every CSS property that uses those variables instantly updates. No second stylesheet, no duplicate rules, no JavaScript changing individual element styles. One attribute change, and the entire visual layer shifts. The operating system can also trigger this automatically through the prefers-color-scheme media query, which detects whether the user has system-wide dark mode enabled.

CSS Zen Garden: The Proof That CSS Controls Everything Visual

In 2003, Dave Shea launched CSS Zen Garden (csszengarden.com) with a challenge: take this single HTML file and make it look completely different using only CSS. Hundreds of designers responded. The same content -- same headings, same paragraphs, same structure -- was transformed into minimalist layouts, art-deco masterpieces, hand-drawn illustrations, and futuristic interfaces. None of them changed a single HTML tag.

This project proved a principle that still holds: HTML is structure, CSS is presentation, and the two should never be tangled. If your design requires changing your HTML to look different, your architecture is wrong. If your HTML requires specific CSS to be understood, your semantics are wrong. Keep them separate, and both become more powerful.

Write semantic HTML
Add CSS for layout and style
Test at multiple screen sizes
Refine typography and spacing
Professional result

Why Google's Homepage Loads So Fast

Google's homepage is famously minimal: a logo, a search bar, two buttons, a few links. But the speed is not just about simplicity. It is about how little HTML and CSS the browser has to parse. The entire page is about 200KB including the logo. By comparison, the average webpage in 2026 is around 2.5MB -- twelve times larger. Less HTML means fewer elements to lay out. Less CSS means fewer styles to compute. Fewer images means fewer network requests. Google's engineers obsessively measure "Time to Interactive" -- how long until the user can type and search. Every unnecessary CSS rule, every extra <div>, every unoptimized image adds milliseconds. At Google's scale, milliseconds matter: a 100ms increase in page load time costs them 1% of search revenue.

Answers to Questions Students Actually Ask

Do I need to learn HTML/CSS before JavaScript? Yes. JavaScript manipulates HTML and CSS -- it adds elements, removes elements, changes classes, updates styles. If you do not understand what you are manipulating, you will write JavaScript that technically works but creates fragile, unmaintainable pages. Learn HTML/CSS first, then JavaScript enhances what you already understand. Two weeks of focused HTML/CSS practice gives you enough foundation to start JavaScript confidently.

Is CSS hard? The basics are straightforward -- colors, fonts, spacing. The tricky parts are centering (flexbox solved this), understanding specificity (which rule wins when two rules conflict), and responsive layouts (media queries and testing across devices). CSS is more craft than science. You improve by building things and fixing what looks wrong, not by memorizing properties. The good news: the hardest parts of CSS from 10 years ago (vertical centering, equal-height columns, complex layouts) have been completely solved by flexbox and grid.

What about website builders like Wix or Squarespace? They generate HTML and CSS for you. Fine for a personal portfolio or a small business site where you need something live in a day. Limiting for anything custom, anything high-performance, or anything that needs to scale. Understanding HTML and CSS means you are never locked into a builder, never limited by its templates, and never paying $20/month for something you could host for free. It is the difference between renting and owning.

Should I use a CSS framework? If you are building something real, yes. Tailwind if you want full design control. Bootstrap if you want pre-built components and speed. But learn vanilla CSS first. Frameworks abstract away the underlying mechanics, and when something breaks -- and it will -- you need to understand what is happening beneath the abstraction. Write CSS from scratch for your first few projects. Then use a framework for everything after.

How do I get better at design without being a designer? Study sites you admire. Open DevTools (F12 in any browser) and inspect how they built their layouts. Notice their spacing, their font sizes, their color palette. Recreate pages you like from scratch -- not to copy, but to understand the decisions. Follow Refactoring UI by Adam Wathan and Steve Schoger for practical design advice aimed at developers. The gap between developer design and designer design closes fast once you internalize a few core principles: consistency, whitespace, typography hierarchy, and color restraint.

Where HTML and CSS Take You Next

HTML and CSS are the entry point, not the destination. From here, the paths branch. JavaScript makes your pages interactive -- handling clicks, fetching data, updating content without reloading. Frameworks like React, Vue, and Next.js manage complex interfaces by combining HTML templates, CSS styles, and JavaScript logic into reusable components. CSS architecture (BEM, CSS Modules, CSS-in-JS) solves the problem of maintaining stylesheets across large teams and thousands of components. Design systems codify your visual language into a shared library so every page across your entire product looks consistent.

But all of those paths assume you can build a clean, semantic HTML page with well-structured CSS that works across screen sizes. That is the foundation. Every React component renders HTML. Every design system is implemented in CSS. Every framework is an abstraction over the same two languages you just learned. Master them, and everything else becomes a refinement of what you already know.

The takeaway: HTML provides structure. CSS provides style. Together, they are the visual layer of every website on Earth. The browser reads HTML to know what to display and CSS to know how to display it. Flexbox and grid replaced 15 years of layout hacks. Responsive design ensures your pages work on every device. Frameworks like Tailwind and Bootstrap accelerate production work. But the core skill -- writing clean, semantic HTML with thoughtful, consistent CSS -- is what separates developers who can build professional interfaces from those who cannot.