Skip to main content

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!
You're Learning HTML5

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:

  1. You write HTML code in a text file (.html)
  2. Browser reads the HTML tags
  3. Browser displays formatted content
  4. 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 -->
Self-Closing Tags

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

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​

index.html
<!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:

  1. Open Notepad (Windows) or TextEdit (Mac)
  2. 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>
  1. Save as my-page.html
  2. Double-click the file to open in your browser
  3. 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​

<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 type
  • name = form field name
  • placeholder = hint text
  • required = must fill out

Attributes Reference Table​

AttributeUsed OnPurposeExample
href<a>Link destination<a href="url">
src<img>, <script>File source<img src="pic.jpg">
alt<img>Image description<img alt="Cat">
idAny elementUnique identifier<div id="main">
classAny elementGroup classifier<p class="intro">
styleAny elementInline CSS<p style="color:red">
titleAny elementTooltip 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! πŸš€