HTML — the complete reference
Foundations
What HTML is, what it isn't, and the skeleton every document shares.
What is HTML?
HTML stands for HyperText Markup Language. It is not a programming language — it has no logic, no loops, no conditions. It provides the structure and meaning of a webpage.
- HTML → structure / meaning
- CSS → presentation / style
- JavaScript → behavior / logic
When the browser parses HTML it builds an in-memory tree of elements called the DOM (Document Object Model). JavaScript then manipulates that DOM.
Document structure
Every HTML page shares the same skeleton. Know what each part is for:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Website</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
<!DOCTYPE html>— tells the browser this is HTML5 and to render in standards mode.<html lang="en">— the root element;langdeclares the document language (helps screen readers and search engines).<head>— machine-readable metadata: title, meta, links, scripts.<meta>— metadata about the document.<title>— the tab name and the search-engine headline.<body>— everything the user actually sees.
Elements, tags & attributes
The difference matters. An element is the whole thing; tags are its opening/closing markers; an attribute configures it.
<p class="text">Hello</p>
p→ element / tagclass→ attribute"text"→ attribute value
Common attributes: id, class, style, title, hidden, lang, dir, data-*, aria-*.
Block vs inline
Block elements start on a new line and occupy the full available width. Inline elements flow within surrounding text.
<!-- block -->
<div> <p> <h1> <section> <article> <header>
<footer> <nav> <main> <ul> <table> <form>
<!-- inline -->
<span> <a> <strong> <em> <img> <input>
<button> <code>
Understand this before you touch CSS layout — display behavior is built on it.
Comments
<!-- This is a comment. It is not rendered. -->
HTML entities
Reserved characters and special symbols are written as entities so the parser doesn't misinterpret them:
no-break space
< <
> >
& &
" "
' '
<p>5 < 10</p>
Rendered as: 5 < 10
Text & Semantics
Choosing the right element for meaning — not for appearance. CSS owns appearance.
Headings h1–h6
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<h1> per page, then nest in order. Style with CSS, not bigger heading numbers.Paragraph, br, hr
<p>A paragraph of text.</p>
<p>Line one<br>line two</p>
<hr>
<p>— paragraph.<br>— a single line break inside text.<hr>— a thematic break (renders as a rule).
<br> tags for vertical spacing — that's a CSS margin/padding job.strong, em, mark, del, ins
<strong>Important</strong> semantic emphasis / importance
<em>Emphasized</em> stress emphasis
<mark>Highlighted</mark> marked / highlighted
<del>Old price</del> deleted content
<ins>New price</ins> inserted content
strong→ strong importance (browsers render bold).em→ stress emphasis (rendered italic).mark→ highlighted, like a marker pen.del/ins→ corrections and edits; perfect for showing a strike-through "old → new" pattern.
sub, sup, small
H<sub>2</sub>O
x<sup>2</sup>
<small>Copyright information</small>
sub → subscript (chemistry), sup → superscript (exponents), small → side comments / legal fine print.
code & pre
<p>Run <code>npm start</code> to begin.</p>
<pre>
Hello
World
</pre>
code→ inline code inside prose.pre→ preformatted text; whitespace and newlines are preserved verbatim. Put acodeinsideprefor a code block.
blockquote & q
<blockquote cite="https://example.com/source">
This is a quotation.
</blockquote>
<p>He said, <q>Hello</q>.</p>
blockquote → a block-level quotation; q → a short inline quotation.
abbr, cite, time
<abbr title="HyperText Markup Language">HTML</abbr>
<cite>Clean Code</cite>
<time datetime="2026-08-13">August 13, 2026</time>
abbr→ abbreviation, full form intitle.cite→ the title of a creative work.time→ a machine-readable date/time indatetime— great for SEO and structured data.
Links & Navigation
The web is a web because of links. Get href right and everything else follows.
The anchor tag
<a href="https://example.com">Visit</a>
href is the destination. Without it the link does nothing.
Relative vs absolute URLs
<!-- absolute: full address -->
<a href="https://example.com/about">About</a>
<!-- relative: relative to the current page -->
<a href="about.html">About</a>
<!-- root-relative: relative to the site root -->
<a href="/images/logo.png">Logo</a>
Use relative URLs inside your own site so it keeps working when deployed.
Fragment links
A link to a section of a page, using an element's id:
<a href="#contact">Contact</a>
<section id="contact">
...
</section>
target & rel
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
Visit
</a>
target="_blank"→ open in a new tab.rel="noopener"→ the new page can't accesswindow.opener(security + performance).rel="noreferrer"→ hides the referrer.
target="_blank" with rel="noopener".mailto / tel
<a href="mailto:test@example.com">Email</a>
<a href="tel:+880123456789">Call</a>
These launch the visitor's mail app / phone dialer instead of navigating.
Images & Media
Pictures, sound, video and embedded content — and the performance habits that come with them.
The img element
<img src="image.jpg" alt="A mountain">
src is the image source. alt is the alternative text — describe the image's meaning, not its appearance.
alt text
<!-- bad: no alt -->
<img src="cat.jpg">
<!-- good: describes the image -->
<img src="cat.jpg" alt="White cat sitting on a chair">
<!-- decorative: empty alt is intentional -->
<img src="decoration.png" alt="">
Missing alt hurts accessibility and SEO. For decorative images, an empty alt="" tells screen readers to skip it.
width, height, loading
<img src="image.jpg" alt="A mountain" width="800" height="500" loading="lazy">
width/height— reserve space so the layout doesn't jump while loading.loading="lazy"— browser defers the download until the image is near the viewport.
Responsive images: srcset / sizes
Give the browser candidates with srcset and rules with sizes. It picks the best file for the viewport and device:
<img
src="small.jpg"
srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 480px, (max-width: 1000px) 800px, 1200px"
alt="Mountain">
The w values are the image's intrinsic width in pixels; the browser compares them against sizes and its own knowledge of the device.
The picture element
For art direction — showing genuinely different crops per screen size:
<picture>
<source media="(max-width: 600px)" srcset="mobile.jpg">
<source media="(min-width: 601px)" srcset="desktop.jpg">
<img src="desktop.jpg" alt="Landscape">
</picture>
The img inside is the fallback — it must always be present.
Audio
<audio controls>
<source src="song.mp3" type="audio/mpeg">
</audio>
Useful attributes: controls, autoplay, loop, muted, preload. Browsers commonly block autoplay with sound.
Video
<video controls poster="thumbnail.jpg" width="800">
<source src="video.mp4" type="video/mp4">
</video>
Know: controls, autoplay, muted, loop, poster, preload, width, height.
iframe & embedded content
iframe embeds another document. You'll meet it with YouTube, Google Maps, dashboards and external widgets.
<iframe src="https://example.com" title="Example website">
</iframe>
Always give iframes a title. embed and object exist for plugins/legacy content — you'll rarely need them.
SVG
<svg width="100" height="100" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" fill="tomato"/>
</svg>
SVG is vector and lives in the DOM — it scales crisply and can be styled and scripted like any element.
Canvas
<canvas id="myCanvas" width="300" height="150"></canvas>
Canvas is a bitmap drawing surface — it draws nothing until JavaScript does. SVG → vector/DOM; Canvas → pixel drawing.
Lists & Tables
Structured content. Backend data almost always ends up in tables.
Unordered & ordered lists
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<ol>
<li>Install</li>
<li>Configure</li>
<li>Run</li>
</ol>
ul → unordered (bullets), ol → ordered (numbers), items wrapped in li. Nest ul/ol only inside li.
Description lists
<dl>
<dt>HTML</dt>
<dd>Markup language for webpages.</dd>
<dt>CSS</dt>
<dd>Styles webpages.</dd>
</dl>
dl → description list, dt → term, dd → description.
Tables
<table>
<caption>Students</caption>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanzir</td>
<td>23</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>1</td>
</tr>
</tfoot>
</table>
caption→ table title.thead/tbody/tfoot→ header, body, footer groups.tr→ row,th→ header cell,td→ data cell.
Use tables only for real tabular data — never for page layout.
colspan / rowspan
<td colspan="2">Total</td> <!-- spans 2 columns -->
<td rowspan="3">Merged</td> <!-- spans 3 rows -->
Forms
Master forms. They are the gateway between your frontend and any backend.
Form basics
<form action="/submit" method="POST">
<label for="name">Name</label>
<input type="text" id="name" name="name">
<button type="submit">Submit</button>
</form>
action → where data goes. method → how it travels (GET/POST).
label & fieldset
<label for="email">Email</label>
<input id="email" type="email">
<fieldset>
<legend>Shipping address</legend>
...
</fieldset>
label+ matchingfor/idties a caption to its field — clicking the label focuses the input, and screen readers announce it.fieldsetgroups related fields,legendnames the group.
Input types
The type attribute changes behavior, validation and the on-screen keyboard. Know these:
text, password, email, number, tel, url, search,
date, time, datetime-local, month, week,
color, file, checkbox, radio, range, hidden,
submit, reset, button
<input type="email">
<input type="password">
<input type="number" min="1" max="10">
<input type="date">
<input type="file">
<input type="checkbox">
<input type="radio">
<input type="color">
type="email" alone gives you format validation for free.
Form attributes
<input type="email" name="email" placeholder="Enter email"
required autocomplete="email" maxlength="254">
<input type="number" min="18" max="100" step="1">
<input type="text" minlength="8" pattern="[A-Za-z]+">
<input disabled>
<input readonly value="fixed">
<input type="checkbox" checked>
<select><option selected>Chosen</option></select>
<input type="file" accept="image/png, image/jpeg">
Know: name, value, placeholder, required, disabled, readonly, checked, selected, min, max, step, minlength, maxlength, pattern, autocomplete, autofocus, multiple, accept.
Radio buttons
Same name = same group = only one selectable:
<label>
<input type="radio" name="gender" value="male"> Male
</label>
<label>
<input type="radio" name="gender" value="female"> Female
</label>
Checkboxes
<label>
<input type="checkbox" name="skills" value="html"> HTML
</label>
<label>
<input type="checkbox" name="skills" value="css"> CSS
</label>
Multiple boxes may be checked; they share a name but each keeps its own value.
Select / optgroup
<select name="country">
<option value="bd">Bangladesh</option>
<option value="in">India</option>
</select>
<select multiple>...</select>
<select>
<optgroup label="Asia">
<option>Bangladesh</option>
<option>Japan</option>
</optgroup>
</select>
Textarea
<textarea name="message" rows="5" cols="30"
placeholder="Write something..."></textarea>
Multi-line text input — note it has content, not a value attribute.
File upload
<input type="file">
<input type="file" multiple>
<input type="file" accept="image/png, image/jpeg">
File uploads travel in multipart/form-data — set it on the form:
<form action="/upload" method="POST" enctype="multipart/form-data">
Built-in validation
<input required>
<input type="email" required>
<input minlength="8">
<input maxlength="20">
<input type="number" min="18" max="100">
<input pattern="[A-Za-z]+">
The name attribute
<input type="text" name="username">
name is the key the value is sent under. Without it, the field's value generally won't be submitted at all. A field with no name sends nothing.
GET vs POST
<form action="/search" method="GET">...</form> <!-- search, filters, reading -->
<form action="/login" method="POST">...</form> <!-- login, create, upload -->
- GET → data in the URL query string (
/search?q=html). Good for searches and filters. - POST → data in the request body. Good for login, registration, creating, uploading.
enctype
application/x-www-form-urlencoded <!-- default -->
multipart/form-data <!-- REQUIRED for file uploads -->
text/plain <!-- rarely used -->
Know when multipart/form-data is necessary: whenever a file is in the form.
Client vs server validation
HTML validation helps the user; backend validation protects your app.
Frontend validation
↓
Backend validation
↓
Database
Semantic HTML
Name the box by its meaning, not its appearance. Your markup is your documentation.
Why semantics matter
Semantic elements describe what content is. Using them improves:
- Accessibility — assistive tech reads the meaning.
- SEO — search engines understand the structure.
- Maintainability — a page you can read like a document.
- Readability —
navbeatsdiv class="navigation".
The layout elements
<header> <!-- page or section intro: logo, headline, nav -->
<nav> <!-- navigation links -->
<main> <!-- the dominant content (one per page) -->
<section> <!-- a themed group of content -->
<article> <!-- self-contained: post, card, comment -->
<aside> <!-- tangentially related: sidebar, ads, notes -->
<footer> <!-- closing info: author, links, copyright -->
Also remember figure + figcaption for illustrations and address for contact info.
A complete semantic page
<body>
<header>
<nav>...</nav>
</header>
<main>
<section>...</section>
<article>...</article>
<aside>...</aside>
</main>
<footer>...</footer>
</body>
div / span & div soup
<div>...</div> <!-- block-level generic container -->
<p>Hello <span>world</span></p> <!-- inline generic container -->
div and span are last resorts when no semantic element fits. Avoid this:
<div>
<div>
<div>
<div>...
That's div soup — use semantic elements instead.
id vs class
<div id="header">...</div> <!-- unique in the document -->
<div class="card">...</div> <!-- reusable -->
id — unique, one per document, used by links, JS and CSS targeting. class — reusable, heavily used with CSS and JavaScript. Duplicate IDs are invalid.
data-* attributes
Your own private attributes for JavaScript — the dataset API reads them:
<button data-user-id="123">Delete</button>
<div data-product-id="55" data-category="laptop"></div>
button.dataset.userId; // "123"
div.dataset.productId; // "55"
div.dataset.category; // "laptop"
Global attributes
Work on every element. You won't use them all daily — but know what each does:
id, class, style, title, lang, dir,
hidden, tabindex, contenteditable, draggable,
spellcheck, translate, data-*
Head, Meta & SEO
Invisible to users, critical to browsers, screen readers and search engines.
The head element
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Website</title>
<link rel="stylesheet" href="style.css">
</head>
The head holds metadata, not visible content.
meta essentials
<title>My Website</title> <!-- tab + search headline -->
<meta charset="UTF-8"> <!-- character encoding -->
<meta name="viewport"
content="width=device-width, initial-scale=1.0"> <!-- responsive -->
<meta name="description"
content="My website description"> <!-- SEO snippet -->
<meta name="robots" content="index, follow"> <!-- crawler rules -->
<link rel="canonical" href="https://example.com/page"> <!-- original URL -->
<link rel="icon" href="favicon.ico"> <!-- tab icon -->
External CSS & JS
<link rel="stylesheet" href="style.css">
<script src="script.js"></script> <!-- blocks parsing -->
<script src="script.js" defer></script> <!-- runs after HTML parsed -->
<script src="script.js" async></script> <!-- loads & runs ASAP -->
Understand the defer / async difference before JavaScript — it changes when your code runs.
base & favicon
<base href="/"> <!-- base URL for all relative links (rare, know it) -->
<link rel="icon" href="/favicon.ico" type="image/x-icon">
SEO basics
HTML does a lot of SEO work for you:
- One proper
<title>and<meta name="description">per page. - Semantic headings — exactly one
<h1>. - Semantic HTML structure (
header/main/footer). - Meaningful link text — not "click here".
- Image
alttext. rel="canonical"for duplicate-safe URLs.- Structured data basics (JSON-LD) for rich results.
Accessibility
Not optional. The best accessibility is native HTML used correctly.
Why accessibility
Accessibility (a11y) means the page works for everyone — keyboard users, screen readers, low-vision users, and more. Semantic HTML is the foundation; ARIA fills the gaps.
Labels, alt & native controls
<!-- label your fields -->
<label for="email">Email</label>
<input id="email" type="email">
<!-- describe your images -->
<img src="profile.jpg" alt="John Doe">
<!-- use a real button, not a clickable div -->
<button type="submit">Submit</button>
<!-- <div onclick="submitForm()">Submit</div> -- DON'T -->
Use native controls whenever possible — they're keyboard-accessible and announced correctly for free.
ARIA
ARIA = Accessible Rich Internet Applications. It adjusts the accessibility tree when native HTML isn't enough.
<button aria-label="Close menu">×</button>
aria-label <!-- accessible name -->
aria-labelledby <!-- name from another element -->
aria-describedby <!-- extra description -->
aria-hidden <!-- hide from AT -->
aria-expanded <!-- open/closed state -->
aria-controls <!-- what this controls -->
aria-current <!-- current item (e.g. page) -->
aria-live <!-- announce dynamic updates -->
role <!-- override/define a role -->
Keyboard accessibility
<button>Submit</button> <!-- natively focusable + Enter/Space works -->
<div tabindex="0">...</div> <!-- made focusable manually (sparingly) -->
Everything interactive should be reachable and operable by keyboard. tabindex exists, but prefer native elements.
The accessibility tree
Browsers derive a separate accessibility tree from the DOM for assistive technology. Semantic elements map to meaningful roles automatically — that's why:
<button>Submit</button> <!-- becomes role="button", keyboard-able -->
<div>Submit</div> <!-- no role, no behavior -->
Modern Elements
Today's HTML ships with interactive primitives that used to require JavaScript.
details / summary
Native accordion — no JavaScript required:
<details>
<summary>What is HTML?</summary>
<p>HTML structures webpages.</p>
</details>
Add open to start expanded.
dialog
<dialog id="modal">
<p>Confirmation</p>
<button>Close</button>
</dialog>
Modals, confirmations and dialogs. JavaScript calls showModal() / close() on it.
template
An inert HTML fragment cloned later by JavaScript:
<template id="cardTemplate">
<div class="card">
<h2></h2>
</div>
</template>
The browser renders nothing until the template's content is cloned into the DOM.
Web Components concept
<my-card></my-card>
Custom elements, Shadow DOM and templates together form Web Components. You don't need to master them before React — just understand the idea of reusable, encapsulated custom tags.
contenteditable
<div contenteditable="true">
Edit this text.
</div>
Makes content editable in the browser — the basis of rich text editors and CMS document editing.
hidden
<div hidden>Hidden content</div>
Removes the element from rendering entirely. Different from merely hiding visually with CSS (visibility keeps the space, hidden doesn't).
noscript
<noscript>
Please enable JavaScript.
</noscript>
Displayed only when JavaScript is unavailable.
Performance & Security
HTML that loads fast and doesn't leak trust.
defer / async
<script src="script.js"></script> <!-- blocks HTML parsing -->
<script src="script.js" defer></script> <!-- waits for HTML, runs in order -->
<script src="script.js" async></script> <!-- downloads async, runs when ready -->
defer is usually the right default for scripts that touch the page.
loading="lazy"
<img src="large-image.jpg" loading="lazy" alt="...">
<iframe src="map.html" loading="lazy" title="Map"></iframe>
Defer off-screen media. One of the cheapest performance wins in HTML.
Resource hints
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preload" href="font.woff2" as="font" type="font/woff2" crossorigin>
<link rel="prefetch" href="next-page.html">
<link rel="dns-prefetch" href="https://api.example.com">
preconnect→ start the connection early.preload→ fetch a critical resource now.prefetch→ fetch for a future navigation.dns-prefetch→ resolve the domain early.
Use them only when there's a real performance reason.
iframe security
<iframe
src="https://untrusted.example"
sandbox="allow-scripts"
loading="lazy"
referrerpolicy="no-referrer"
title="Embedded content">
</iframe>
sandbox restricts what the embedded document can do; allow and referrerpolicy tighten it further. Embedding third-party content has real security implications.
Security checklist
rel="noopener"on everytarget="_blank"link.sandbox+referrerpolicyon untrusted iframes.autocomplete="off"where sensitive (sparingly).- Never put secrets in HTML, comments or frontend code.
- Validate and sanitize everything again on the backend.
URLs & Paths
Critical the moment you deploy a real site.
Absolute / relative / root-relative
https://example.com/images/logo.png <!-- absolute -->
images/logo.png <!-- relative -->
/images/logo.png <!-- root-relative -->
#contact <!-- fragment -->
Absolute → full address. Relative → from the current file. Root-relative → from the site root (needs a real server/domain). Fragment → a section of the page.
Path practice
Common project layout and how files reference each other:
project/
index.html
about.html
css/style.css
js/script.js
images/logo.png
about.html links to:
css/style.css <!-- same-level sibling folder -->
images/logo.png
index.html
The DOM
The bridge between your markup and JavaScript.
The DOM tree
The browser turns your markup into a tree of objects:
Document
↓ html
↓ head
↓ body
↓ h1
↓ "Hello"
JavaScript interacts with this tree:
document.querySelector('h1')
document.getElementById('header')
element.textContent
element.innerHTML
element.classList
HTML vs DOM
Don't confuse them. HTML is your source markup. DOM is the browser's live, in-memory representation that JavaScript reads and modifies. You can change the DOM without touching the source HTML at all.
Mistakes & Deprecated
What gives beginner markup away — and what to use instead.
Common mistakes
<!-- 1. <br> stacks for spacing -- use CSS margin/padding -->
<br><br><br>
<!-- 2. headings chosen by size -- choose by structure -->
<h1>Small text</h1>
<!-- 3. div for everything -- use semantic elements -->
<div class="nav">...</div>
<!-- 4. missing alt -->
<img src="cat.jpg">
<!-- 5. unlabelled inputs -->
<input type="email">
<!-- 6. clickable divs -->
<div onclick="...">...</div>
<!-- 7. duplicate ids -->
<div id="card"></div>
<div id="card"></div>
Deprecated tags
Recognize these old tags, but never use them in new projects — CSS replaces them all:
<center> <font> <marquee> <big> <strike> <u>
Internationalization
<html lang="en"> <!-- English -->
<html lang="bn"> <!-- Bangla -->
<span lang="bn">বংাংা</span> <!-- mixed-content span -->
dir="ltr" <!-- left-to-right -->
dir="rtl" <!-- right-to-left (Arabic, etc.) -->
Tools & Validation
How to check your work, and how to organize it.
HTML validation
Run your pages through an HTML validator to catch:
- Invalid nesting
- Missing required attributes
- Duplicate IDs
- Invalid markup
- Accessibility issues
Tools: the W3C Nu Validator, or browser extension validators. Worth it on serious projects.
Browser DevTools
HTML learning isn't complete without DevTools (Chrome/Edge → F12 or Ctrl+Shift+I). You should be able to:
- Inspect and edit HTML live
- Inspect attributes and the DOM
- Find and tweak CSS
- Check accessibility
- Watch network requests
- View page source
- Test responsive layouts
Project file structure
project/
↓ index.html
↓ about.html
↓ css/
↓ style.css
↓ js/
↓ script.js
↓ images/
↓ logo.png
↓ assets/
Frameworks will change the structure later, but the underlying ideas (separate concerns, one page = one file) stay.
Mental Model
Step back and see how the pieces fit.
HTML + CSS + JS
WEBSITE
↓
HTML CSS JS
Structure Style Behavior
↓
Browser
↓
DOM
<button id="btn">Click me</button>
HTML creates the button. CSS styles it. JavaScript makes it do something.
What not to memorize
You do not need to memorize every tag. Think in terms of intent:
- "I need a navigation menu" →
<nav> - "I need an email field" →
<input type="email"> - "I need a button" →
<button> - "I need an article" →
<article>
Understand what element to choose and why — that's the skill.
Master checklist
If you can work through this without looking up basic syntax, you're ready for CSS. Work it into your muscle memory over a week, then revise monthly.