Web Fundamentals · Lesson 1 of 10 · 4 min
HTML Fundamentals: Structure & Core Elements
This is the first filter in an interview. If you can't explain this, the conversation is already over.
After this, you will be able to explain the foundational structure of an HTML document and the semantic purpose of its core elements. You'll know which tags to use for structure versus content, and why it matters for accessibility and SEO.
Nail the Document Boilerplate
Every HTML document starts with the same four elements. You should be able to write this from memory and explain each part.
<!DOCTYPE html>: This is not a tag. It's an instruction that tells the browser to render the page in "standards mode." Without it, the browser falls back into "quirks mode," which emulates rendering bugs from the 90s. There is no reason to ever omit this.<html>: The root element. Everything else is nested inside. Always add thelangattribute (e.g.,<html lang="en">) to tell screen readers and search engines the page's primary language. It's a small detail that signals professionalism.<head>: Contains metadata. This is where you put the page<title>, character encoding (<meta charset="UTF-8">), viewport settings, and links to CSS (<link>) and JavaScript (<script>). Nothing in the<head>is visible on the page itself.<body>: Contains all visible content. Text, images, buttons—if the user sees it, it goes in the body.
The trap: Being asked the difference between <head> and <body> and giving a fuzzy answer. The separation is absolute: metadata versus visible content.
Use Headings to Create an Outline
Headings (<h1> through <h6>) create the document's structure. They are not for styling text. Screen readers use them to navigate, and search engines use them to understand content hierarchy.
Think of them as a document outline. There should be exactly one <h1> for the main title of the page. Subsections get <h2>s, sub-subsections get <h3>s, and so on. Never skip levels, like going from an <h2> to an <h4>.
An interviewer might ask: "Why not just use a
<div>and make the font bigger with CSS?"Your answer: "Because that throws away all semantic meaning. A
<div>tells a screen reader nothing about the structure of the page, making it difficult for users to navigate. It also hurts SEO, as search crawlers rely on heading tags to determine the page's topic and hierarchy."
Distinguish Content, Generic, and Media Elements
Your primary job is to choose the right element for the content.
Content Elements: These give meaning to what they contain.
<p>: A paragraph of text. The most common text container.<a>: An anchor, or hyperlink. Itshrefattribute is the destination. Usetarget="_blank"to open in a new tab, but do so sparingly.<ul>,<ol>,<li>: For lists.<ul>is an unordered (bulleted) list.<ol>is an ordered (numbered) list.<li>is a list item within either.
Generic Containers: These have no semantic meaning. Use them for styling or scripting hooks when no other element fits.
<div>: A block-level container. It takes up the full width available and starts on a new line. Use it to group larger sections of content.<span>: An inline container. It takes up only the space its content needs and does not break the flow of text. Use it to style a specific word or phrase within a larger block.
The trap: "Divitis"—wrapping everything in a <div>. If your content is a heading, use <h1>. If it's a paragraph, use <p>. Only reach for <div> when you need a generic grouping container.
Media Elements: These embed external content.
<img>: An image. It's a self-closing tag. Thesrcattribute points to the image file. Thealtattribute is mandatory.
Why the alt Attribute is Non-Negotiable
The alt attribute on an <img> tag provides alternative text for an image. It is not optional.
It serves three purposes:
- Accessibility: Screen readers announce the alt text, describing the image to visually impaired users.
- Broken Images: If the image fails to load, the browser displays the alt text.
- SEO: Search engines use alt text to understand what an image contains.
The trap: Forgetting it or thinking it's unimportant. In a professional context, shipping an <img> without an alt attribute is a bug.
If an image is purely decorative and adds no information (e.g., a background pattern), provide an empty alt attribute: alt="". This tells screen readers to ignore it, which is better than them reading out the filename.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Portfolio</title>
</head>
<body>
<h1>Jane Doe's Portfolio</h1>
<p>Welcome! Below are some of my skills and projects.</p>
<div>
<h2>About Me</h2>
<img
src="https://via.placeholder.com/150"
alt="A professional headshot of Jane Doe."
>
<p>
I am a frontend developer with a passion for building accessible
and user-friendly web applications.
</p>
</div>
<div>
<h2>My Skills</h2>
<ul>
<li>HTML5 & Accessibility</li>
<li>CSS3 & SASS</li>
<li>JavaScript (ES6+) & TypeScript</li>
<li>React</li>
</ul>
</div>
<p>
See my work on
<a href="https://github.com/example" target="_blank">GitHub</a>.
</p>
</body>
</html>
Try it
Create a single HTML file named index.html. Structure it as a basic personal bio page with a main heading for your name, a paragraph for a short bio, an image with proper alt text, and an unordered list of three hobbies. Open the file in a browser to see your work.
Next: We'll cover how to structure more complex data with Lists, Tables & Basic Forms.
Lock it in — apply this lesson under interview conditions.