What You'll Learn
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!
- 🌐 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!
HTML Structure & Basics
Basic HTML Document
<!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.
<!-- 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
Text Elements
Headings & Paragraphs
<!-- 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
<!-- 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>
Emphasized text (italic)
Underlined text
Highlighted text
H2O and X2
console.log('Hello')
Line Breaks & Horizontal Rules
<!-- Line Break --> <p>First line<br>Second line</p> <!-- Horizontal Rule (divider) --> <p>Content above</p> <hr> <p>Content below</p>
Links & Images
Hyperlinks
<!-- Basic Link --> <a href="https://google.com">Visit Google</a> <!-- Open in New Tab --> <a href="https://github.com" target="_blank">GitHub</a> <!-- Email Link --> <a href="mailto:[email protected]">Email Us</a> <!-- Phone Link --> <a href="tel:+1234567890">Call Us</a> <!-- Link to Section (Anchor) --> <a href="#about">Go to About Section</a> <!-- Download Link --> <a href="file.pdf" download>Download PDF</a> <!-- Relative Link --> <a href="about.html">About Page</a> <a href="../index.html">Back to Home</a>
💡 Link Target Options
_self - Default, same window
_blank - New window/tab
_parent - Parent frame
_top - Full window
Images
<!-- Basic Image --> <img src="photo.jpg" alt="Description of image"> <!-- Image with Size --> <img src="photo.jpg" alt="Photo" width="300" height="200"> <!-- Clickable Image (Image Link) --> <a href="https://google.com"> <img src="logo.png" alt="Logo"> </a> <!-- Image with Title (tooltip) --> <img src="photo.jpg" alt="Photo" title="Hover text"> <!-- Figure with Caption --> <figure> <img src="photo.jpg" alt="Beautiful sunset"> <figcaption>A beautiful sunset over the ocean</figcaption> </figure>
⚠️ Always Use Alt Text!
The alt attribute is crucial for accessibility (screen readers) and SEO.
Describe the image content clearly and concisely.
Lists
Ordered & Unordered Lists
<!-- 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>
- HTML
- CSS
- JavaScript
- First step
- Second step
- Third step
Tables
HTML Tables
<!-- 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
Forms & Input
HTML Forms
<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.
Semantic HTML
Semantic Elements
Semantic HTML uses meaningful tags that describe the content's purpose, making your code more readable, accessible, and SEO-friendly.
<!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>
✅ Benefits of Semantic HTML
🔍 Better SEO (search engines understand content)
♿ Improved accessibility (screen readers)
📖 More readable code
🎯 Easier maintenance
Media Elements
Video & Audio
<!-- 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
Meta Tags & SEO
Essential Meta Tags
<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)
HTML5 Features
Modern HTML5 Elements
<!-- 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>
Best Practices
HTML Best Practices
Always Use DOCTYPE
Start every HTML document with <!DOCTYPE html>
Use Semantic HTML
Use meaningful tags like <header>, <nav>, <article> instead of generic <div>
Always Close Tags
Close all paired tags properly. Use self-closing tags correctly.
Use Lowercase
Write all tags and attributes in lowercase for consistency.
Add Alt Text to Images
Always include descriptive alt attributes for accessibility.
Validate Your HTML
Use W3C validator to check for errors: validator.w3.org
Indent Your Code
Use proper indentation for nested elements to improve readability.
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
<!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!