HTML Basics
What is HTML?
HTML stands for HyperText Markup Language. It defines the structure and meaning of content
on a web page.
HTML is not a programming language. It is a markup language
that describes elements such as headings, paragraphs, links, images, forms, tables, navigation, and
sections.
<h1>Hello, world!</h1>
<p>This is a paragraph.</p>
HTML is Structural
HTML answers the question:
What is this content?
CSS answers:
How should it look?
JavaScript answers:
How should it behave?
<button>Save</button>
The HTML tells the browser that the content is a button. CSS can style it, while JavaScript can add
behavior.
Tags, Elements, and Attributes
A tag is the syntax used to mark the beginning or end of an element.
An element usually contains an opening tag, content, and a closing tag.
<p>Hello</p>
An attribute provides additional information about an element.
<a href="https://example.com">Visit Example</a>
Document Structure
Basic HTML Document
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
<!DOCTYPE html>
The doctype tells the browser to use modern HTML parsing behavior.
<!DOCTYPE html>
<html>
The <html> element is the root element of the document.
<html lang="en">
...
</html>
The lang attribute identifies the document language.
<head>
The <head> contains document metadata and resources rather than the main visible page
content.
<body>
The <body> contains the content rendered as part of the page.
Elements & Attributes
Block and Inline Content
Modern HTML is primarily organized around semantics rather than a strict block-versus-inline model, but the
distinction remains useful when learning document layout.
<div>Block-level container</div>
<span>Inline content</span>
Opening and Closing Tags
<article>
<h2>Title</h2>
<p>Content</p>
</article>
Void Elements
Some HTML elements do not contain content and therefore do not need closing tags.
<img src="photo.jpg" alt="A mountain">
<br>
<hr>
<input type="text">
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
Boolean Attributes
Boolean attributes represent an on/off state. Their presence generally means true.
<input type="checkbox" checked>
<input type="text" disabled>
<button autofocus>Save</button>
Attribute Values
Attribute values should generally be quoted.
<img src="photo.jpg" alt="A landscape">
Text Content
Headings
<h1>Main Page Title</h1>
<h2>Major Section</h2>
<h3>Subsection</h3>
<h4>Smaller Section</h4>
<h5>Detail</h5>
<h6>Lowest Heading Level</h6>
Headings should represent the hierarchy of the document rather than merely being chosen for their visual
size.
Paragraphs
<p>This is a paragraph of text.</p>
Strong and Emphasis
<strong>Important information</strong>
<em>Emphasized text</em>
Use these elements for their meaning, not just their appearance.
Other Useful Text Elements
<mark>Highlighted text</mark>
<small>Small print</small>
<del>Deleted text</del>
<ins>Inserted text</ins>
<sub>Subscript</sub>
<sup>Superscript</sup>
Quotes
<blockquote cite="https://example.com">
A longer quotation.
</blockquote>
<p>
He said <q>Hello</q>.
</p>
Code and Preformatted Text
<p>Use <code>console.log()</code> to print output.</p>
<pre>
Line one
Line two
Line three
</pre>
Line Breaks and Rules
<p>
First line<br>
Second line
</p>
<hr>
Use <br> for meaningful line breaks, not to create page layout.
Images
Basic Image
<img
src="mountains.jpg"
alt="Snow-covered mountains"
>
The Importance of alt
The alt attribute provides a text alternative for an image. It is important for accessibility
and for cases where the image cannot be displayed.
<img
src="profile.jpg"
alt="Profile photograph of Alex"
>
Decorative images can use an empty alternative:
<img src="divider.svg" alt="">
Width and Height
<img
src="photo.jpg"
alt="A city skyline"
width="800"
height="500"
>
Figure and Caption
<figure>
<img
src="architecture.jpg"
alt="Historic building"
>
<figcaption>
Historic architecture in the city center.
</figcaption>
</figure>
Responsive Images
<picture>
<source
media="(min-width: 900px)"
srcset="large.jpg"
>
<source
media="(min-width: 500px)"
srcset="medium.jpg"
>
<img
src="small.jpg"
alt="A landscape"
>
</picture>
Semantic HTML
What is Semantic HTML?
Semantic HTML uses elements that communicate the purpose of their content.
<header>
<nav>...</nav>
</header>
<main>
<article>
...
</article>
</main>
<footer>
...
</footer>
<header>
Represents introductory content for a page or section.
<nav>
Represents a major navigation section.
<main>
Represents the main content of the document.
<section>
Represents a thematic grouping of content, usually with a heading.
<article>
Represents a self-contained piece of content that could conceptually stand on its own.
<aside>
Represents content related to the surrounding content, such as supporting information or a sidebar.
<footer>
Represents footer content for a page or section.
Semantic Layout Example
<body>
<header>
<h1>Website</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<article>
<h2>Main Article</h2>
<p>Article content.</p>
</article>
<aside>
<h2>Related</h2>
<p>Supporting information.</p>
</aside>
</main>
<footer>
<p>Copyright</p>
</footer>
</body>
Embedded Content
Iframe
<iframe
src="https://example.com"
title="Example website"
width="800"
height="500"
></iframe>
Always provide a useful title for an iframe.
Embedding External Content
Embedded content can include maps, documents, videos, and external applications.
<iframe
src="https://example.com/embed"
title="Embedded application"
></iframe>
Accessibility
Use Semantic Elements
Prefer meaningful HTML elements instead of building everything with generic containers.
<button>Save</button>
Prefer a real button over a clickable generic element.
Use Labels for Form Controls
<label for="email">Email</label>
<input id="email" name="email" type="email">
Use Alt Text
<img
src="logo.png"
alt="Company logo"
>
Use Proper Heading Hierarchy
<h1>Page Title</h1>
<h2>Section</h2>
<h3>Subsection</h3>
<h2>Another Section</h2>
Keyboard Accessibility
Interactive controls should be usable through keyboard interaction. Native HTML controls provide important
behavior automatically.
<button type="button">
Open Menu
</button>
Do Not Use Placeholder as the Label
<label for="username">Username</label>
<input
id="username"
name="username"
type="text"
placeholder="Enter username"
>
A placeholder can provide an example, but it should not replace a proper label.
Common Mistakes
Using div for Everything
<div>
<div>
<div>Navigation</div>
</div>
</div>
Prefer semantic elements such as <nav>, <header>,
<main>, and <footer> when they match the meaning.
Using <br> for Layout
Line breaks should represent meaningful line breaks, not spacing. Use CSS for layout and spacing.
Missing Alt Text
<img src="logo.png">
Provide an appropriate alt value unless the image is purely decorative.
Unlabeled Form Controls
<input type="email">
Prefer an explicitly associated label.
<label for="email">Email</label>
<input id="email" type="email" name="email">
Clickable div Instead of Button
<div onclick="save()">
Save
</div>
A real button provides native semantics and keyboard behavior.
<button type="button">
Save
</button>
Real Page Example
Complete Semantic HTML Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
<meta
name="description"
content="A simple example of a semantic HTML page."
>
<title>Developer Notes</title>
<link rel="stylesheet" href="coding.css">
</head>
<body>
<header>
<h1>Developer Notes</h1>
<nav>
<a href="#html">HTML</a>
<a href="#css">CSS</a>
<a href="#javascript">JavaScript</a>
</nav>
</header>
<main>
<section id="html">
<h2>HTML</h2>
<article>
<h3>Semantic HTML</h3>
<p>
Semantic elements describe the purpose of content.
</p>
</article>
</section>
<section id="css">
<h2>CSS</h2>
<article>
<h3>Styling</h3>
<p>
CSS controls presentation and layout.
</p>
</article>
</section>
<section id="javascript">
<h2>JavaScript</h2>
<article>
<h3>Behavior</h3>
<p>
JavaScript adds dynamic behavior to the page.
</p>
</article>
</section>
</main>
<footer>
<p>Developer Notes</p>
</footer>
</body>
</html>
HTML Cheat Sheet
Document Structure
<!DOCTYPE html>
<html lang="en">
<head>...</head>
<body>...</body>
</html>
Text
<h1>Heading</h1>
<p>Paragraph</p>
<strong>Important</strong>
<em>Emphasis</em>
<mark>Highlight</mark>
<small>Small text</small>
<code>code</code>
<pre>preformatted</pre>
Links and Media
<a href="...">Link</a>
<img src="..." alt="...">
<audio controls>...</audio>
<video controls>...</video>
<iframe src="..." title="..."></iframe>
Structure
<header>...</header>
<nav>...</nav>
<main>...</main>
<section>...</section>
<article>...</article>
<aside>...</aside>
<footer>...</footer>
Lists
<ul>
<li>Item</li>
</ul>
<ol>
<li>Item</li>
</ol>
<dl>
<dt>Term</dt>
<dd>Description</dd>
</dl>
Forms
<form>
<label for="name">Name</label>
<input id="name" name="name" type="text">
<textarea></textarea>
<select>
<option>Option</option>
</select>
<button type="submit">Submit</button>
</form>
Tables
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alex</td>
</tr>
</tbody>
</table>
Learning Path
1. Learn the Document Structure
Start with html, head, body, headings, paragraphs, links, and the
basic document skeleton.
2. Learn Core Elements
Practice text, lists, links, images, tables, forms, and media.
3. Learn Semantic HTML
Understand header, nav, main, section,
article, aside, and footer.
4. Learn Accessibility
Practice labels, alt text, heading hierarchy, native controls, and meaningful document structure.
5. Learn Forms
Understand input types, validation attributes, labels, buttons, fieldsets, and submission behavior.
6. Learn Metadata
Study titles, descriptions, viewport settings, icons, stylesheets, and document language.
7. Build Complete Pages
Stop learning tags in isolation. Build complete pages using semantic structure and accessible controls.
8. Learn HTML with CSS and JavaScript
HTML provides structure and meaning. CSS controls presentation. JavaScript adds behavior and interactivity.