Introduction to HTML and Web Structure
TL;DR
HTML is like the skeleton of a webpage, organizing content with specific tags. These tags create elements, outlining the different parts of what you see online. Understanding HTML is the first step to building anything on the web.
1. The Mental Model
Think of HTML as a recipe for a cake. It tells you what ingredients (content) go where and how they're structured, but it doesn't tell you how to decorate it. That's for other tools.
2. The Core Material
HTML, or HyperText Markup Language, is the standard language for creating web pages. It uses "markup" to define the structure and content of a page.
What are HTML Elements and Tags?
An HTML document is made up of elements. Each element describes a piece of content, like a paragraph, a heading, or an image. Elements are created using tags.
A tag typically comes in pairs: an opening tag and a closing tag.
For example:
<p> is the opening tag for a paragraph.
</p> is the closing tag for a paragraph.
The content goes between the tags:
<p>This is a paragraph of text.</p>
Some tags are self-closing (or "void tags") because they don't enclose content. They represent something inserted directly into the page. An image tag is a good example:
<img src="image.jpg" alt="A descriptive image text">
Anatomy of an HTML Document
Every basic HTML document follows a similar structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome!</h1>
<p>This is some content on my page.</p>
</body>
</html>
Let's break it down:
<!DOCTYPE html>: This isn't an HTML tag; it's a declaration that tells the browser which HTML version to expect (in this case, HTML5). You always put this at the very top.
<html lang="en">: This is the root element of an HTML page. All other elements go inside it. The lang="en" attribute specifies the language of the document, which helps search engines and accessibility tools.
<head>: This section contains meta-information about the HTML document. Things in the head aren't directly visible on the page itself but are crucial for its behavior and presentation.
<meta charset="UTF-8">: Specifies the character encoding, allowing browsers to correctly display characters from different languages.
*