Om Pandey
HTML Complete Guide

Complete HTML Guide

The Foundation of Every Website

Master HTML5 from absolute zero to hero level! Learn the building blocks of web development and create stunning, semantic, and accessible web pages.

Easy to Learn Semantic Tags Responsive Accessible

What You'll Learn

1

Introduction to HTML

HTML (HyperText Markup Language) is the standard markup language for creating web pages. It describes the structure and content of a webpage using elements and tags.

💡 What is HTML?

HTML is NOT a programming language - it's a markup language. It tells the browser how to structure and display content. Think of it as the skeleton of a website!

Why Learn HTML?
  • 🌐 Foundation of all web pages
  • 📱 Required for web development
  • ✨ Easy to learn and understand
  • 🎯 Works on all browsers
  • 🚀 Gateway to CSS and JavaScript

✅ What You'll Build

By the end of this guide, you'll be able to create complete, semantic, and accessible web pages from scratch!

2

HTML Structure & Basics

Basic HTML Document

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Meta Information -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- Page Title -->
    <title>My First Web Page</title>
</head>
<body>
    <!-- Content Goes Here -->
    <h1>Hello, World!</h1>
    <p>This is my first web page.</p>
</body>
</html>

💡 Structure Breakdown

<!DOCTYPE html> - Tells browser this is HTML5
<html> - Root element
<head> - Contains meta information
<body> - Contains visible content

HTML Tags & Elements

HTML uses tags to define elements. Most tags come in pairs: opening and closing tags.

tags-example.html
<!-- Paired Tags -->
<h1>Opening Tag - Content - Closing Tag</h1>

<!-- Self-Closing Tags -->
<img src="image.jpg" alt="Description">
<br>
<hr>

<!-- Tags with Attributes -->
<a href="https://google.com" target="_blank">Google</a>

<!-- Nested Tags -->
<div>
    <p>Paragraph inside a div</p>
</div>

⚠️ Important Rules

• Tags must be properly nested
• Close all paired tags
• Use lowercase for tags (best practice)
• Always quote attribute values

3

Text Elements

Headings & Paragraphs

headings.html
<!-- Headings (h1 to h6) -->
<h1>Main Heading (Largest)</h1>
<h2>Sub Heading</h2>
<h3>Sub Sub Heading</h3>
<h4>Heading Level 4</h4>
<h5>Heading Level 5</h5>
<h6>Smallest Heading</h6>

<!-- Paragraph -->
<p>This is a paragraph. Paragraphs contain text content.</p>

<p>
    Paragraphs can span multiple lines
    and will be displayed as a single block.
</p>

💡 Best Practice

Use only one <h1> per page (main title). Use headings in order (don't skip from h1 to h4). This helps with SEO and accessibility!

Text Formatting

text-formatting.html
<!-- Bold -->
<strong>Important text (semantic)</strong>
<b>Bold text (visual only)</b>

<!-- Italic -->
<em>Emphasized text (semantic)</em>
<i>Italic text (visual only)</i>

<!-- Underline -->
<u>Underlined text</u>

<!-- Strikethrough -->
<s>Strikethrough text</s>
<del>Deleted text</del>

<!-- Mark/Highlight -->
<mark>Highlighted text</mark>

<!-- Small Text -->
<small>Small print text</small>

<!-- Subscript & Superscript -->
H<sub>2</sub>O
X<sup>2</sup>

<!-- Code -->
<code>console.log('Hello')</code>

<!-- Preformatted Text -->
<pre>
    Text with    spaces
    and line breaks
    preserved
</pre>

<!-- Blockquote -->
<blockquote>
    This is a quote from someone famous.
</blockquote>
Browser Preview
Important text (bold)
Emphasized text (italic)
Underlined text
Highlighted text
H2O and X2
console.log('Hello')

Line Breaks & Horizontal Rules

breaks.html
<!-- Line Break -->
<p>First line<br>Second line</p>

<!-- Horizontal Rule (divider) -->
<p>Content above</p>
<hr>
<p>Content below</p>
5

Lists

Ordered & Unordered Lists

lists.html
<!-- Unordered List (bullets) -->
<ul>
    <li>HTML</li>
    <li>CSS</li>
    <li>JavaScript</li>
</ul>

<!-- Ordered List (numbers) -->
<ol>
    <li>First step</li>
    <li>Second step</li>
    <li>Third step</li>
</ol>

<!-- Nested Lists -->
<ul>
    <li>Frontend
        <ul>
            <li>HTML</li>
            <li>CSS</li>
            <li>JavaScript</li>
        </ul>
    </li>
    <li>Backend
        <ul>
            <li>Python</li>
            <li>Node.js</li>
        </ul>
    </li>
</ul>

<!-- Description List -->
<dl>
    <dt>HTML</dt>
    <dd>HyperText Markup Language</dd>
    
    <dt>CSS</dt>
    <dd>Cascading Style Sheets</dd>
</dl>
Browser Preview
Unordered List:
  • HTML
  • CSS
  • JavaScript
Ordered List:
  1. First step
  2. Second step
  3. Third step
6

Tables

HTML Tables

table.html
<!-- Basic Table -->
<table border="1">
    <!-- Table Header -->
    <thead>
        <tr>
            <th>Name</th>
            <th>Age</th>
            <th>City</th>
        </tr>
    </thead>
    
    <!-- Table Body -->
    <tbody>
        <tr>
            <td>Om Pandey</td>
            <td>25</td>
            <td>Kathmandu</td>
        </tr>
        <tr>
            <td>John Doe</td>
            <td>30</td>
            <td>New York</td>
        </tr>
    </tbody>
    
    <!-- Table Footer (optional) -->
    <tfoot>
        <tr>
            <td colspan="3">Total: 2 people</td>
        </tr>
    </tfoot>
</table>

<!-- Colspan & Rowspan -->
<table border="1">
    <tr>
        <th colspan="2">Merged Columns</th>
    </tr>
    <tr>
        <td>Cell 1</td>
        <td>Cell 2</td>
    </tr>
</table>

💡 Table Tags

<table> - Table container
<thead> - Table header
<tbody> - Table body
<tfoot> - Table footer
<tr> - Table row
<th> - Header cell
<td> - Data cell

7

Forms & Input

HTML Forms

form.html
<form action="/submit" method="POST">
    
    <!-- Text Input -->
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>
    
    <!-- Email Input -->
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>
    
    <!-- Password Input -->
    <label for="password">Password:</label>
    <input type="password" id="password" name="password">
    
    <!-- Number Input -->
    <label for="age">Age:</label>
    <input type="number" id="age" name="age" min="1" max="100">
    
    <!-- Radio Buttons -->
    <p>Gender:</p>
    <input type="radio" id="male" name="gender" value="male">
    <label for="male">Male</label>
    
    <input type="radio" id="female" name="gender" value="female">
    <label for="female">Female</label>
    
    <!-- Checkboxes -->
    <p>Skills:</p>
    <input type="checkbox" id="html" name="skills" value="html">
    <label for="html">HTML</label>
    
    <input type="checkbox" id="css" name="skills" value="css">
    <label for="css">CSS</label>
    
    <!-- Select Dropdown -->
    <label for="country">Country:</label>
    <select id="country" name="country">
        <option value="">Select...</option>
        <option value="nepal">Nepal</option>
        <option value="usa">USA</option>
        <option value="uk">UK</option>
    </select>
    
    <!-- Textarea -->
    <label for="message">Message:</label>
    <textarea id="message" name="message" rows="4"></textarea>
    
    <!-- File Upload -->
    <label for="file">Upload File:</label>
    <input type="file" id="file" name="file">
    
    <!-- Date Input -->
    <label for="date">Date:</label>
    <input type="date" id="date" name="date">
    
    <!-- Submit Button -->
    <button type="submit">Submit</button>
    
    <!-- Reset Button -->
    <button type="reset">Reset</button>
    
</form>

💡 Input Types

HTML5 provides many input types: text, email, password, number, date, time, color, range, url, tel, search, and more!

⚠️ Form Validation

Use required for mandatory fields. Use pattern for custom validation. Use appropriate input types for automatic browser validation.

8

Semantic HTML

Semantic Elements

Semantic HTML uses meaningful tags that describe the content's purpose, making your code more readable, accessible, and SEO-friendly.

semantic.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Semantic HTML Example</title>
</head>
<body>
    
    <!-- Header Section -->
    <header>
        <nav>
            <ul>
                <li><a href="#home">Home</a></li>
                <li><a href="#about">About</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </nav>
    </header>
    
    <!-- Main Content -->
    <main>
        
        <!-- Article Section -->
        <article>
            <header>
                <h1>Article Title</h1>
                <p>Published on <time datetime="2025-01-25">January 25, 2025</time></p>
            </header>
            
            <section>
                <h2>Introduction</h2>
                <p>Article content...</p>
            </section>
            
            <section>
                <h2>Main Content</h2>
                <p>More content...</p>
            </section>
            
            <footer>
                <p>Author: Om Pandey</p>
            </footer>
        </article>
        
        <!-- Aside (Sidebar) -->
        <aside>
            <h3>Related Articles</h3>
            <ul>
                <li><a href="#">Article 1</a></li>
                <li><a href="#">Article 2</a></li>
            </ul>
        </aside>
        
    </main>
    
    <!-- Footer Section -->
    <footer>
        <p>© 2025 My Website. All rights reserved.</p>
    </footer>
    
</body>
</html>
<header>Site or section header
<nav>Navigation links
<main>Main content
<article>Independent content
<section>Thematic grouping
<aside>Sidebar content
<footer>Footer section
<figure>Image with caption
<time>Date/time
<mark>Highlighted text

✅ Benefits of Semantic HTML

🔍 Better SEO (search engines understand content)
♿ Improved accessibility (screen readers)
📖 More readable code
🎯 Easier maintenance

9

Media Elements

Video & Audio

media.html
<!-- Video -->
<video width="640" height="360" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.webm" type="video/webm">
    Your browser doesn't support video.
</video>

<!-- Video with Autoplay & Loop -->
<video autoplay loop muted playsinline>
    <source src="background.mp4" type="video/mp4">
</video>

<!-- Audio -->
<audio controls>
    <source src="audio.mp3" type="audio/mpeg">
    <source src="audio.ogg" type="audio/ogg">
    Your browser doesn't support audio.
</audio>

<!-- Embedded YouTube Video -->
<iframe 
    width="560" 
    height="315" 
    src="https://www.youtube.com/embed/VIDEO_ID" 
    frameborder="0" 
    allowfullscreen>
</iframe>

<!-- SVG (Scalable Vector Graphics) -->
<svg width="100" height="100">
    <circle cx="50" cy="50" r="40" fill="red" />
</svg>

💡 Media Attributes

controls - Show playback controls
autoplay - Auto-start (muted required for most browsers)
loop - Repeat playback
muted - Start muted
poster - Video thumbnail image

10

Meta Tags & SEO

Essential Meta Tags

meta-tags.html
<head>
    <!-- Character Encoding -->
    <meta charset="UTF-8">
    
    <!-- Viewport for Responsive Design -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- Page Title (SEO Important!) -->
    <title>My Awesome Website - Learn Web Development</title>
    
    <!-- Meta Description (SEO) -->
    <meta name="description" content="Learn web development with HTML, CSS, and JavaScript. Complete tutorials and guides.">
    
    <!-- Keywords (less important for SEO now) -->
    <meta name="keywords" content="HTML, CSS, JavaScript, web development">
    
    <!-- Author -->
    <meta name="author" content="Om Pandey">
    
    <!-- Favicon -->
    <link rel="icon" href="favicon.ico" type="image/x-icon">
    
    <!-- Open Graph (Social Media Sharing) -->
    <meta property="og:title" content="My Awesome Website">
    <meta property="og:description" content="Learn web development">
    <meta property="og:image" content="https://example.com/image.jpg">
    <meta property="og:url" content="https://example.com">
    
    <!-- Twitter Card -->
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="My Awesome Website">
    <meta name="twitter:description" content="Learn web development">
    <meta name="twitter:image" content="https://example.com/image.jpg">
    
    <!-- Robots (Search Engine Instructions) -->
    <meta name="robots" content="index, follow">
</head>

✅ SEO Best Practices

• Use descriptive, unique titles (50-60 characters)
• Write compelling meta descriptions (150-160 characters)
• Use semantic HTML
• Add alt text to all images
• Use proper heading hierarchy (h1-h6)

11

HTML5 Features

Modern HTML5 Elements

html5-features.html
<!-- Canvas for Graphics -->
<canvas id="myCanvas" width="400" height="300"></canvas>

<!-- Progress Bar -->
<label for="progress">Loading:</label>
<progress id="progress" value="70" max="100">70%</progress>

<!-- Meter (Gauge) -->
<label for="meter">Disk Usage:</label>
<meter id="meter" value="0.6" min="0" max="1">60%</meter>

<!-- Details & Summary (Accordion) -->
<details>
    <summary>Click to expand</summary>
    <p>Hidden content that shows when clicked.</p>
</details>

<!-- Dialog (Modal) -->
<dialog id="myDialog">
    <h2>Dialog Title</h2>
    <p>Dialog content</p>
    <button onclick="document.getElementById('myDialog').close()">Close</button>
</dialog>

<!-- Datalist (Autocomplete) -->
<input list="browsers" name="browser">
<datalist id="browsers">
    <option value="Chrome">
    <option value="Firefox">
    <option value="Safari">
    <option value="Edge">
</datalist>

<!-- Output (Calculation Result) -->
<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
    <input type="number" id="a" value="5"> +
    <input type="number" id="b" value="10"> =
    <output name="result">15</output>
</form>
12

Best Practices

HTML Best Practices

1

Always Use DOCTYPE

Start every HTML document with <!DOCTYPE html>

2

Use Semantic HTML

Use meaningful tags like <header>, <nav>, <article> instead of generic <div>

3

Always Close Tags

Close all paired tags properly. Use self-closing tags correctly.

4

Use Lowercase

Write all tags and attributes in lowercase for consistency.

5

Add Alt Text to Images

Always include descriptive alt attributes for accessibility.

6

Validate Your HTML

Use W3C validator to check for errors: validator.w3.org

7

Indent Your Code

Use proper indentation for nested elements to improve readability.

8

Optimize for Performance

Minimize HTTP requests, compress images, use lazy loading for images and videos.

✅ Accessibility Checklist

✓ Use semantic HTML
✓ Add alt text to images
✓ Use proper heading hierarchy
✓ Label all form inputs
✓ Provide keyboard navigation
✓ Ensure sufficient color contrast
✓ Use ARIA attributes when needed

Complete HTML Template

template.html
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Meta Tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Your page description">
    
    <!-- Title -->
    <title>Your Page Title</title>
    
    <!-- Favicon -->
    <link rel="icon" href="favicon.ico">
    
    <!-- CSS -->
    <link rel="stylesheet" href="style.css">
</head>
<body>
    
    <!-- Header -->
    <header>
        <nav>
            <!-- Navigation -->
        </nav>
    </header>
    
    <!-- Main Content -->
    <main>
        <!-- Your content here -->
    </main>
    
    <!-- Footer -->
    <footer>
        <p>© 2025 Your Name. All rights reserved.</p>
    </footer>
    
    <!-- JavaScript -->
    <script src="script.js"></script>
</body>
</html>

🎉 Congratulations!

You've mastered HTML from zero to hero! You now have the foundation to create amazing web pages. Keep practicing and start building projects!