HTML Fundamentals
Every web page you have ever visited began as a plain text file full of angle brackets. HTML â HyperText Markup Language â is the layer that turns that text into a document with headings, paragraphs, lists, links, and images. It is not a programming language: it cannot loop, calculate, or hold state on its own. Its job is to describe what the content is, while CSS decides how it looks and JavaScript decides how it behaves.
That separation is the most important idea in front-end development. When you mark a line as a top-level heading rather than merely large bold text, you give browsers, screen readers, search-engine crawlers, and translation tools a reliable signal about the document's structure. This lesson builds the vocabulary and the habits you will reuse in every project that follows.
Markup, Not Programming
An HTML file is a tree of elements. Each element is created by a pair of tags â an opening tag and a closing tag â with content in between. Some elements, such as images or line breaks, are void: they carry meaning on their own and need no closing tag.
Elements nest inside one another, and the nesting order defines the document tree. A paragraph inside an article belongs to that article; move it outside and its meaning changes even if the visible pixels stay the same. Browsers hand this tree to your page as the Document Object Model, which CSS selectors match against and JavaScript queries. Getting the tree right is therefore not a style preference â it is the foundation every other technology on the page depends on.
The Skeleton Every Page Starts From
Every HTML document opens with a doctype declaration, which tells the browser to parse in standards mode rather than a legacy quirks mode that still emulates bugs from the 1990s. Inside the root html element the content splits into a head, holding metadata the user does not see directly, and a body, holding everything rendered on screen.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bakery Order Form</title>
<meta name="description" content="Order sourdough, rye, and pastries for weekend pickup.">
</head>
<body>
<header>
<h1>Harbour Street Bakery</h1>
</header>
<main>
<section>
<h2>Weekend specials</h2>
<p>Sourdough loaves are baked fresh every Saturday morning.</p>
</section>
</main>
<footer>
<p>© 2026 Harbour Street Bakery</p>
</footer>
</body>
</html>
The lang attribute on the root element is not decoration. Screen readers pick a pronunciation voice from it, and browsers use it to choose hyphenation and font fallbacks. The charset and viewport tags belong in the head of nearly every page: without the charset declaration, accented characters can be mis-decoded into garbage, and without the viewport tag, mobile browsers render as if the screen were a desktop monitor.
Elements, Attributes, and Nesting Rules
Attributes ride along in an opening tag as name-value pairs and configure the element. An anchor without an href is not a link; an image without an alt is invisible to anyone using a screen reader. Attribute names are case-insensitive in HTML, but convention and the HTML5 specification favour lowercase with hyphens.
Three nesting rules prevent most structural bugs. First, close elements in the reverse order you opened them. Second, never nest interactive elements such as anchors inside one another â browsers flatten the result unpredictably. Third, block-level elements such as paragraphs cannot legally contain other block elements; an article cannot live inside a paragraph even if a browser still displays it. Valid structure keeps the accessibility tree accurate and makes CSS selectors behave the way you expect.
Text Semantics: Picking the Right Element
The heading levels h1 through h6 form an outline of the page. Skip a level if the design calls for it, but never jump from h1 straight to h4 purely because h4 looks the right size â control appearance with CSS instead.
| Element | Use it for | Common misuse |
|---|---|---|
| h1 | The main topic of the page, usually one per page | Multiple h1s competing for the same section |
| h2 to h6 | Section and subsection outline | Choosing a level for its default font size |
| strong | Strong importance that changes meaning | Bold styling of ordinary labels |
| em | Emphasis that changes spoken stress | Italic decoration only |
| mark | Highlighting relevant text such as search matches | Brand colors applied everywhere |
| code | Inline machine instructions or identifiers | Quoting speech |
| blockquote | Long quotations with an attribution | Indenting for visual effect |
| time | A machine-readable date or duration | Writing dates as free text only |
Links and Images in Practice
Links are the web's founding feature, and their quality shows up in small details. Descriptive anchor text such as "Saturday pickup times" beats "click here" for screen-reader users, who often pull up a list of every link on the page, and for search engines, which read anchor text as a signal of the destination.
<article>
<h2>Sourdough, 800 g</h2>
<img src="/img/sourdough-800.jpg"
alt="Round sourdough loaf with a scored crust on a wooden board"
width="640" height="480" loading="lazy">
<p>Fermented for 18 hours. <mark>Saturday only.</mark></p>
<p>
<a href="/orders/sourdough-800" aria-label="Order the 800 gram sourdough loaf">
Order this loaf
</a>
</p>
</article>
Always declare width and height attributes on images: the browser reserves the right box before the file downloads, which prevents the layout from jumping as content loads. The loading="lazy" attribute defers offscreen images until the reader scrolls near them. Alt text should describe the information the image conveys. An empty alt attribute is correct for purely decorative images, but omitting the attribute entirely is not â screen readers then read the file name aloud.
đĄA quick alt-text test
Ask yourself: if the image failed to load and only its alt text remained, would the reader still get the point? If yes, the alt is good. If the image is decoration, use an empty alt attribute so assistive tech skips it.
Lists: Ordered, Unordered, and Description
Use an unordered list when sequence does not matter, an ordered list when it does â recipe steps, ranked results, numbered instructions â and a description list for term-and-definition pairs. Nesting a sublist inside a list item is valid; starting a brand-new list for every item is not. Screen readers announce how many items a list contains, so proper list markup gives users a mental map of the content before they hear a single word.
How Browsers Recover From Bad Markup
HTML parsing is famously forgiving. A missing closing tag usually does not blank the page â the parser guesses where elements should end, drops truly invalid nesting, and carries on. That forgiveness is a feature for readers and a trap for developers: the tree the browser builds can differ from the one you imagined, which is why a CSS rule mysteriously fails to match or a stray element inherits the wrong styles. Validate your markup during development so the forgiveness never turns into a production mystery.
Common Mistakes
Using heading levels for font size
Fix: Pick the level that fits the document outline, then restyle it with CSS.
Alt text that repeats the filename, or no alt attribute at all
Fix: Describe the image's purpose; use an empty alt attribute for decorative images.
Generic link text such as 'click here' or 'read more'
Fix: Write anchor text that names the destination, even when read out of context.
Forgetting the lang attribute on the root element
Fix: Set lang on the html tag so screen readers choose the correct voice.
Key Takeaways
- HTML describes meaning and structure; CSS and JavaScript handle presentation and behavior.
- Every document needs a doctype, a charset, a viewport tag, a title, and a lang attribute.
- Attributes configure elements â a missing href or alt changes how the page is experienced.
- Heading levels form an outline; choose them for structure, never for default size.
- Browsers repair invalid markup, so validate during development to catch silent structural bugs.
- Descriptive link text and meaningful alt text are accessibility features, not extras.
Extended Learning: Beyond the Basics
Key Concepts Summary
This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.
Prerequisite Knowledge
Before studying this topic in depth, ensure you understand:
- Basic definitions and terminology
- Core formulas and their derivations
- Common applications in real-world scenarios
- Typical pitfalls and misconceptions
Step-by-Step Walkthrough
Let us work through a complete example to solidify understanding:
Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.
Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.
Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.
Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.
Common Mistakes to Avoid
- Misidentifying the problem type â Always start by categorizing the problem
- Incorrect formula application â Verify the formula applies to your specific case
- Unit errors â Always check units are consistent throughout
- Sign errors â Pay careful attention to positive and negative values
- Rounding too early â Keep full precision until the final answer
- Forgetting constraints â Check that solutions satisfy all given conditions
Real-World Applications
Understanding this concept is essential for:
- Advanced problem solving in examinations
- Building intuition for more complex topics
- Developing analytical thinking skills
- Applying mathematical reasoning to practical situations
Practice Exercises
- Basic: Solve 5 problems of increasing difficulty using the core concept.
- Intermediate: Apply the concept to word problems with multiple steps.
- Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
- Challenge: Create your own problem that requires this concept plus additional knowledge.
Interview and Exam Tips
- Common question patterns: Identify which exam or interview formats test this topic
- Time management: Practice completing problems within time constraints
- Common traps: Know the typical mistakes examiners set as distractors
- Verification strategy: Develop a quick method to check your answer
Related Topics
- Previous Topic â Build on the foundation laid here
- Next Topic â See how this concept extends to more advanced material
- Practice Problems â Additional exercises with solutions
- Video Explanation â Visual walkthrough of key concepts
Quick Reference Card
| Concept | Formula/Rule | Key Insight | Common Use |
|---|---|---|---|
| Core Definition | See main text | Understand the intuition | Foundation for all applications |
| Key Formula | See main text | Memorize the derivation | Direct problem solving |
| Special Case | See main text | Recognize when it applies | Simplifies complex problems |
| Edge Case | See main text | Know the limitations | Avoids errors |
Further Reading
For students who want to go deeper:
- Standard textbooks on the subject
- Research papers applying this concept
- Online courses with video explanations
- Practice problem collections with detailed solutions