Introduction to HTML Structure and Elements
From the https://youtu.be/ceaowpc97PE?si=2qAArktHkrSVwbKY curriculum
Introduction to HTML Structure and Elements
TL;DR
HTML is the standard language for creating web pages, using a structure of elements nested within each other. Each element tells the browser what kind of content it's displaying and how it relates to other content. Understanding this basic structure is key to building any website.
1. The Mental Model
Think of HTML like building with LEGOs. Each LEGO brick is an element, and you connect them to build a larger structure (your web page). Some bricks contain others, forming a clear hierarchy.
2. The Core Material
HTML stands for HyperText Markup Language. It's not a programming language; it's a markup language that describes the structure of web content. Your web browser reads this HTML and renders it visually.
An HTML document is made up of elements. Most elements consist of an opening tag, some content, and a closing tag.
<p>This is a paragraph.</p>
Here, <p> is the opening tag, </p> is the closing tag, and "This is a paragraph." is the content. The whole thing is a p element.
Some elements are self-closing or void elements because they don't have content in the traditional sense, so they don't need a closing tag. Examples include <img> (for images) and <br> (for a line break).
<img src="my-image.jpg" alt="Description of my image">
<br>
Elements can have attributes, which provide additional information about the element. Attributes are placed inside the opening tag and usually come in name="value" pairs. In the <img> example above, src and alt are attributes.
The basic structure of an HTML page is a hierarchy:
graph TD
A["<!DOCTYPE html>"] --> B["<html>"]
B --> C["<head>"]
B --> D["<body>"]
C --> E["<meta charset='utf-8'>"]
C --> F["<title>Page Title</title>"]
D --> G["<h1>Main Heading</h1>"]
D --> H["<p>Some paragraph text.</p>"]
D --> I["<img src='image.jpg' alt='An image'>"]
Let's break down these essential structural elements:
The Document Type Declaration (<!DOCTYPE html>)

Photo by Markus Winkler on Pexels
This isn't an HTML tag; it's an instruction to the browser about which version of HTML the page is written in. For modern HTML5, it's always <!DOCTYPE html>.
The <html> Element

Photo by César Gaviria on Pexels
This is the root element of every HTML page. All other content and elements go inside it. It usually includes a lang attribute, like <html lang="en">, to declare the primary language of the document.
The <head> Element

Photo by Suki Lee on Pexels
This section contains metadata about the HTML document. Metadata is data about the data. Things inside <head> are generally not displayed directly on the web page itself, but they are crucial for browsers, search engines, and other web services.
<meta charset="utf-8">: Defines the character encoding for the document, ensuring text displays correctly across different systems.<title>: Sets the title that appears in the browser tab or window title bar.- Other common
<head>elements include links to stylesheets (<link>) and scripts (<script>), and other meta tags for SEO or responsiveness.
The <body> Element

Photo by RAY LEI on Pexels
This is where all the visible content of your web page lives. Everything you see on a web page – text, images, links, videos, etc. – is placed inside the <body> element.
Inside the <body>, you'll use many different elements to structure your content:
- Headings (
<h1>to<h6>): Define section headings, from the most important (<h1>) to the least important (<h6>). - Paragraphs (
<p>): Used for blocks of text. - Images (
<img>): Embed images into the page. - Links (
<a>): Create hyperlinks to other pages or resources.
3. Worked Example
Let's build a very simple HTML page to show how these elements fit together. Imagine you want to create a page about your favorite animal.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Favorite Animal: The Red Panda</title>
</head>
<body>
<h1>The Amazing Red Panda</h1>
<p>Red pandas (Ailurus fulgens) are small arboreal mammals native to the eastern Himalayas and southwestern China. They are known for their distinctive reddish-brown fur and long, bushy tail.</p>
<img src="red-panda.jpg" alt="A cute red panda sitting on a tree branch.">
<p>Despite their name, they are not closely related to giant pandas. They primarily eat bamboo, but also consume eggs, birds, and insects.</p>
<p>Want to learn more? Visit the <a href="https://en.wikipedia.org/wiki/Red_panda">Red Panda Wikipedia page</a>.</p>
</body>
</html>
In this example:
* <!DOCTYPE html> and <html> set up the document.
* <head> contains the page title and character encoding.
* <body> holds all the content you see:
* An <h1> for the main heading.
* <p> tags for paragraphs of text.
* An <img> tag to display an image (assuming red-panda.jpg is in the same folder).
* An <a> tag to create a link to Wikipedia.
4. Key Takeaways
- HTML uses elements (made of opening and closing tags, e.g.,
<p>...</p>) to structure content. - Some elements are self-closing (e.g.,
<img>) and don't need a separate closing tag. - Attributes (e.g.,
src,alt,href) provide extra information for elements within their opening tag. - The basic HTML document structure includes
<!DOCTYPE html>,<html>,<head>, and<body>. - The
<head>contains metadata (like<title>) not directly visible on the page. - The
<body>contains all the visible content of your web page.
Common Mistakes to Avoid
- Forgetting closing tags: This often leads to unexpected display issues. Always check that every opening tag has a matching closing tag (unless it's a self-closing element).
- Incorrect nesting: Elements must be properly nested. Don't do
<b><i>text</b></i>; it should be<b><i>text</i></b>. - Putting visible content in
<head>: Remember,<head>is for metadata. Anything you want to appear on the page goes in<body>. - Using HTML for styling: While older HTML had some styling tags, modern practice separates content (HTML) from presentation (CSS). Avoid using old-fashioned HTML styling tags like
<font>.
5. Now Try It
Open a plain text editor (like Notepad on Windows, TextEdit on Mac, or VS Code). Create a new file and save it as myfirstpage.html. Copy the "Red Panda" example HTML into it. Then, open that myfirstpage.html file in your web browser.
What success looks like: You should see a simple web page titled "My Favorite Animal: The Red Panda" in your browser tab, displaying the heading, text, and an image (or a broken image icon if red-panda.jpg doesn't exist), and a clickable link to Wikipedia. Experiment by changing the text or adding another paragraph!
Frequently asked about Introduction to HTML Structure and Elements
Get the full https://youtu.be/ceaowpc97PE?si=2qAArktHkrSVwbKY curriculum
Clone the complete plan to your dashboard for unlimited AI-generated notes, practice quizzes, and a personalised revision schedule.
Create Free Account