Introduction
Introductionβ
Every website you've ever visitedβGoogle, Facebook, YouTube, your favorite blogβis built with HTML. It's the universal language of the web, and you're about to learn it!
What is HTML? πβ
HTML stands for HyperText Markup Language. Let's break that down:
- HyperText = Text with links (you can click to jump to other pages)
- Markup = Tags that describe content (headings, paragraphs, images)
- Language = A standard way to communicate with web browsers
Simple Definition:
HTML is a set of instructions that tells web browsers how to display content. It's like a blueprint for web pages.
Real-World Analogy π°β
Think of HTML like a newspaper:
βββββββββββββββββββββββββββββββ
β THE DAILY WEB β β Heading (<h1>)
βββββββββββββββββββββββββββββββ€
β Breaking News! β β Subheading (<h2>)
β β
β Today was an exciting day β β Paragraph (<p>)
β in the world of coding... β
β β
β β’ Item one β β List (<ul><li>)
β β’ Item two β
β β
β [Click here for more] β β Link (<a>)
β β
β [ Image here ] β β Image (<img>)
βββββββββββββββββββββββββββββββ
HTML tags label each piece of content (just like a newspaper labels headlines, body text, and images).
History: A Quick Timeline π β
1991 β HTML Created by Tim Berners-Lee
ββ Basic tags for scientific documents
1995 β HTML 2.0 (First Standard)
ββ Tables, forms added
1999 β HTML 4.01 (Major Update)
ββ Stylesheets, scripting support
2014 β HTML5 (Modern Standard) β
ββ Video, audio, semantic tags
ββ Mobile-friendly features
ββ What we use today!
This guide teaches HTML5βthe latest and most powerful version. Everything you learn here is modern and widely supported!
How HTML Works πβ
You Write HTML β Browser Reads It β User Sees Webpage
Step by Step:
- You write HTML code in a text file (
.html) - Browser reads the HTML tags
- Browser displays formatted content
- User sees a beautiful web page!
Example:
<!-- You Write This: -->
<h1>Welcome!</h1>
<p>This is my website.</p>
<!-- Browser Shows This: -->
Welcome! (big and bold)
This is my website. (normal text)
What is a Tag? π·οΈβ
Tags are the building blocks of HTML. They tell the browser what each piece of content is.
Tag Structureβ
<tagname>Content goes here</tagname>
β β β
Opening tag Content Closing tag
Most tags come in pairs:
- Opening tag:
<h1>(starts the element) - Content: The text or media inside
- Closing tag:
</h1>(ends the elementβnote the/)
Common Tagsβ
<h1>Main Heading</h1> <!-- Largest heading -->
<h2>Subheading</h2> <!-- Smaller heading -->
<p>This is a paragraph.</p> <!-- Regular text -->
<a href="url">Link</a> <!-- Clickable link -->
<img src="image.jpg"> <!-- Image (self-closing!) -->
<strong>Bold text</strong> <!-- Bold -->
<em>Italic text</em> <!-- Italic -->
Some tags don't need a closing tag because they don't contain content:
<img src="photo.jpg"> β
No closing tag needed
<br> β
Line break
<hr> β
Horizontal line
In HTML, you use tags to define the structure and content of a web page. Tags are enclosed in angle brackets (< >) and are used to create various elements, such as headings, paragraphs, images, links, lists, tables, and forms.β
Example of a tag:
<tagname>Content goes here</tagname>
For instance, to create a heading, you would use the <h1> tag like this:
<h1>This is a Heading</h1>
The content between the opening and closing tags is displayed on the web page. HTML offers a wide variety of tags, each serving a specific purpose, and combining them allows for diverse layouts and designs.
Once your HTML code is written, save it as a text file with a ".html" extension. You can open it in a web browser to see how it looks. HTML can be used to create anything from simple static pages to complex web applications with dynamic content and interactivity.
Your First HTML Document πβ
Every HTML document follows the same basic structure. Let's build one step by step!
The Complete Structureβ
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Website!</h1>
<p>This is my first paragraph.</p>
</body>
</html>
Output in browser:
Welcome to My Website!
This is my first paragraph.
Understanding Each Part π§©β
Let's break down what each section does:
1. <!DOCTYPE html> - Document Type Declarationβ
<!DOCTYPE html>
What it does: Tells the browser "This is an HTML5 document!"
Why it matters: Without it, browsers might display your page incorrectly.
Must know: Always put this as the very first line!
2. <html> - The Root Elementβ
<html>
<!-- Everything goes inside here -->
</html>
What it does: Container for the entire HTML document
Think of it as: The outer box that holds everything
3. <head> - Document Metadataβ
<head>
<title>My Website</title>
<!-- Other info about the page -->
</head>
What it does: Contains information about the page (not visible to users)
Common contents:
<title>- Page title (shows in browser tab)<meta>- Page description, keywords<link>- Stylesheet connections<script>- JavaScript connections
Not visible: Content in <head> doesn't appear on the page!
4. <title> - Page Titleβ
<title>My Awesome Website</title>
What it does: Sets the text shown in:
- Browser tab
- Bookmarks
- Search engine results
Browser Tab: [My Awesome Website] | β§
β
Comes from <title>
5. <body> - Page Contentβ
<body>
<!-- Everything users see goes here -->
<h1>Heading</h1>
<p>Paragraph</p>
</body>
What it does: Contains all visible content
Includes: Text, images, videos, linksβeverything users interact with!
6. <h1> - Main Headingβ
<h1>This is a Heading</h1>
What it does: Creates the largest, most important heading
Visual: Big, bold text (usually)
Hierarchy: <h1> to <h6> (h1 biggest β h6 smallest)
7. <p> - Paragraphβ
<p>This is a paragraph.</p>
What it does: Regular text content
Visual: Normal-sized text with spacing above and below
Visual Structureβ
βββββββββββββββββββββββββββββββββββ
β <!DOCTYPE html> β Declaration
βββββββββββββββββββββββββββββββββββ€
β <html> β Root start
β βββββββββββββββββββββββββββββ β
β β <head> β β Metadata
β β <title>Page Title</...> β β (not visible)
β β </head> β β
β βββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββββββ β
β β <body> β β Visible content
β β <h1>Heading</h1> β β β Users see this
β β <p>Text...</p> β β β And this
β β </body> β β
β βββββββββββββββββββββββββββββ β
β </html> β Root end
βββββββββββββββββββββββββββββββββββ
Try It Yourself! βοΈβ
Create your first web page:
- Open Notepad (Windows) or TextEdit (Mac)
- Copy this code:
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>I just created my first web page!</p>
</body>
</html>
- Save as
my-page.html - Double-click the file to open in your browser
- You did it! π
HTML Elements in Detail π§±β
Elements are the building blocks of HTML. An element is the complete package: opening tag + content + closing tag.
<p>This is a paragraph.</p>
β β β
Opening Content Closing
tag tag
Element vs Tag vs Contentβ
Element = <p>Hello</p> (the whole thing)
Tag = <p> or </p> (just the markers)
Content = Hello (the text inside)
Nested Elements (Elements Inside Elements)β
Elements can contain other elements!
<div>
<h1>Main Title</h1>
<p>This is a <strong>paragraph</strong> with <em>emphasis</em>.</p>
</div>
Visual Structure:
<div>
ββ <h1>Main Title</h1>
ββ <p>
ββ "This is a "
ββ <strong>paragraph</strong>
ββ " with "
ββ <em>emphasis</em>
HTML Attributes - Adding Details π·οΈβ
Attributes give extra information about elements. They go in the opening tag.
Attribute Syntaxβ
<tagname attribute="value">Content</tagname>
β β
Name Value
Rules:
- Always in opening tag
- Format:
name="value" - Use double quotes
"" - Separated by spaces if multiple
Common Attributes Examplesβ
1. Links with hrefβ
<a href="https://google.com">Click here</a>
href= hyperlink reference (where to go)- Creates clickable link to Google
2. Images with src and altβ
<img src="photo.jpg" alt="A beautiful sunset">
src= source (image location)alt= alternative text (shown if image fails to load)
3. IDs and Classesβ
<div id="header" class="container">Content</div>
id= unique identifier (only one per page)class= group identifier (can reuse)
4. Input with Multiple Attributesβ
<input type="text" name="username" placeholder="Enter your name" required>
type= input typename= form field nameplaceholder= hint textrequired= must fill out
Attributes Reference Tableβ
| Attribute | Used On | Purpose | Example |
|---|---|---|---|
href | <a> | Link destination | <a href="url"> |
src | <img>, <script> | File source | <img src="pic.jpg"> |
alt | <img> | Image description | <img alt="Cat"> |
id | Any element | Unique identifier | <div id="main"> |
class | Any element | Group classifier | <p class="intro"> |
style | Any element | Inline CSS | <p style="color:red"> |
title | Any element | Tooltip text | <span title="Info"> |
Common Mistakes to Avoid π¨β
Mistake 1: Missing Closing Tagsβ
<!-- β Wrong -->
<p>This is a paragraph.
<p>This is another paragraph.
<!-- β
Right -->
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Mistake 2: Incorrect Nestingβ
<!-- β Wrong (overlapping tags) -->
<p>This is <strong>bold and <em>italic</strong></em>.</p>
<!-- β
Right (properly nested) -->
<p>This is <strong>bold and <em>italic</em></strong>.</p>
Mistake 3: Missing Quotes on Attributesβ
<!-- β Wrong -->
<a href=https://google.com>Link</a>
<!-- β
Right -->
<a href="https://google.com">Link</a>
Mistake 4: Using Spaces in Attribute Values Without Quotesβ
<!-- β Wrong -->
<img src=my photo.jpg>
<!-- β
Right -->
<img src="my photo.jpg">
Quick Reference Cheat Sheet πβ
<!-- Document Structure -->
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
<!-- Common Elements -->
<h1>to <h6> Headings (h1 largest, h6 smallest)
<p> Paragraph
<a> Link
<img> Image
<div> Division/Container
<span> Inline container
<br> Line break
<hr> Horizontal rule
<!-- Common Attributes -->
href="url" Link destination
src="file" File source
alt="text" Alternative text
id="name" Unique ID
class="name" Class name
style="css" Inline styles
Key Takeaways π―β
β
HTML structures web page content
β
Tags label what type of content each piece is
β
Elements include opening tag + content + closing tag
β
Attributes add extra information to elements
β
All HTML documents have the same basic structure
β
The <head> section is for metadata (not visible)
β
The <body> section contains visible content
β
Always close your tags properly
β
Nest elements correctly (no overlapping!)
Next Stepsβ
Now that you understand HTML basics, you're ready to learn about:
- Specific HTML tags and their uses
- How to structure more complex pages
- Semantic HTML for better accessibility
- Forms and user input
- Modern HTML5 features
Let's keep building! π