HTML Fundamentals HTML5
Learn the building blocks of every website
1 What is HTML?
HTML (HyperText Markup Language) is the standard language for creating web pages. It describes the structure and content of a web page using "elements" represented by tags. HTML is not a programming language - it's a markup language that tells browsers how to display content.
📝 Definition
HTML = HyperText Markup Language. "HyperText" refers to links connecting pages. "Markup" means annotating text with tags that describe structure. Browsers read HTML and render visual pages.
🔑 Key Concept: HTML Elements
An HTML element consists of: Opening tag + Content + Closing tag
Example: <p>Hello World</p>
Some elements are self-closing: <img />, <br />
2 HTML Document Structure
Every HTML document follows a specific structure. Understanding this skeleton is essential before adding content. The structure tells browsers what kind of document they're reading and how to process it.
<!-- DOCTYPE tells browser this is HTML5 --> <!DOCTYPE html> <!-- html tag is the root - contains everything --> <!-- lang="en" helps screen readers and search engines --> <html lang="en"> <!-- head contains metadata (not displayed on page) --> <head> <!-- charset defines character encoding --> <meta charset="UTF-8"> <!-- viewport ensures mobile responsiveness --> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- title appears in browser tab --> <title>My First Web Page</title> </head> <!-- body contains all visible content --> <body> <h1>Welcome to My Website</h1> <p>This is my first paragraph.</p> </body> </html>
Welcome to My Website
This is my first paragraph.
3 Your First Web Page
Let's create a complete web page from scratch. Save this code in a file with .html extension
and open it in any web browser.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My First Website</title> </head> <body> <h1>Welcome to My Website!</h1> <p>This is my first webpage. I'm learning HTML!</p> <h2>About Me</h2> <p>I am a web developer in training.</p> <h2>My Hobbies</h2> <ul> <li>Coding</li> <li>Reading</li> <li>Gaming</li> </ul> <p>Contact me at: <a href="mailto:me@example.com">me@example.com</a></p> </body> </html>
💡 How to View Your Page
1. Save the code as index.html
2. Double-click the file to open in browser
3. Or right-click → "Open with" → Choose browser
4 Headings
HTML provides six levels of headings, from <h1> (most important) to <h6> (least important).
Headings create hierarchy and help both users and search engines understand your content structure.
💡 SEO Tip
Use only ONE <h1> per page (main title). Search engines use heading hierarchy
to understand page content. Don't skip levels - go h1 → h2 → h3, not h1 → h3.
<!-- h1 is the main heading - use once per page --> <h1>Main Page Title (h1)</h1> <!-- h2 for major sections --> <h2>Section Heading (h2)</h2> <!-- h3 for subsections within h2 --> <h3>Subsection Heading (h3)</h3> <!-- h4, h5, h6 for deeper nesting --> <h4>Sub-subsection (h4)</h4> <h5>Minor Heading (h5)</h5> <h6>Smallest Heading (h6)</h6>
Main Page Title (h1) Section Heading (h2) Subsection Heading (h3) Sub-subsection (h4) Minor Heading (h5) Smallest Heading (h6)
5 Paragraphs
The <p> tag defines a paragraph. Browsers automatically add space before and after paragraphs.
For line breaks within a paragraph, use <br>.
<!-- Basic paragraphs --> <p>This is the first paragraph. It contains some text that describes the topic. Paragraphs automatically wrap to fit the container width.</p> <p>This is the second paragraph. Notice how browsers add space between paragraphs automatically.</p> <!-- Line break within paragraph --> <p> 123 Main Street<br> New York, NY 10001<br> United States </p> <!-- Horizontal rule (divider line) --> <p>Content above the line</p> <hr> <p>Content below the line</p> <!-- Preformatted text (preserves spacing) --> <pre> This text preserves all spaces and line breaks exactly. </pre>
6 Text Formatting
HTML provides various tags to format text - make it bold, italic, highlighted, or give it semantic meaning.
<!-- Bold text --> <strong>Important text</strong> <!-- Semantic: important --> <b>Bold text</b> <!-- Visual only --> <!-- Italic text --> <em>Emphasized text</em> <!-- Semantic: emphasis --> <i>Italic text</i> <!-- Visual only --> <!-- Other formatting --> <mark>Highlighted text</mark> <del>Deleted text</del> <ins>Inserted text</ins> <sub>Subscript</sub> (H<sub>2</sub>O) <sup>Superscript</sup> (x<sup>2</sup>) <!-- Code and keyboard input --> <code>console.log("Hello")</code> <kbd>Ctrl + C</kbd> <!-- Quotations --> <blockquote> This is a long quote that deserves its own block. </blockquote> <q>This is an inline quote.</q>
Emphasized text Italic text
Highlighted text
H2O (water) x2 (squared)
console.log("Hello")
7 Lists
HTML supports three types of lists: unordered (bullets), ordered (numbers), and description lists. Lists are perfect for navigation menus, feature lists, steps, and any grouped items.
<!-- UNORDERED LIST - bullet points --> <h3>Shopping List (Unordered)</h3> <ul> <li>Apples</li> <li>Bread</li> <li>Milk</li> <li>Cheese</li> </ul> <!-- ORDERED LIST - numbered items --> <h3>Recipe Steps (Ordered)</h3> <ol> <li>Preheat oven to 350°F</li> <li>Mix dry ingredients</li> <li>Add wet ingredients</li> <li>Bake for 25 minutes</li> </ol> <!-- NESTED LIST - list inside list --> <h3>Web Technologies (Nested)</h3> <ul> <li>Frontend <ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> </ul> </li> <li>Backend <ul> <li>Node.js</li> <li>Python</li> </ul> </li> </ul>
Shopping List (Unordered)
• Apples
• Bread
• Milk
• Cheese
Recipe Steps (Ordered)
1. Preheat oven to 350°F
2. Mix dry ingredients
3. Add wet ingredients
4. Bake for 25 minutes
Web Technologies (Nested)
• Frontend
◦ HTML
◦ CSS
◦ JavaScript
• Backend
◦ Node.js
◦ Python
5 Links and Images
Links (<a>) connect pages together - the "Hyper" in HyperText.
Images (<img>) add visual content. Both use attributes to specify their source.
<!-- ========== LINKS ========== --> <!-- External link - opens another website --> <!-- target="_blank" opens in new tab --> <a href="https://google.com" target="_blank"> Visit Google </a> <!-- Internal link - another page on same site --> <a href="about.html">About Us</a> <!-- Anchor link - jumps to section on same page --> <a href="#contact">Go to Contact Section</a> <!-- Email link - opens email client --> <a href="mailto:hello@example.com"> Email Us </a> <!-- Phone link - clickable on mobile --> <a href="tel:+1234567890">Call Us</a> <!-- ========== IMAGES ========== --> <!-- Basic image --> <!-- src = source path, alt = description for accessibility --> <img src="photo.jpg" alt="A beautiful sunset"> <!-- Image with size --> <img src="logo.png" alt="Company Logo" width="200" height="100" > <!-- Image as a link --> <a href="https://example.com"> <img src="banner.jpg" alt="Click to visit"> </a>
Visit Google ← Opens google.com in new tab About Us ← Opens about.html Go to Contact Section ← Scrolls to #contact Email Us ← Opens email client Call Us ← Opens phone app on mobile [🖼️ Image: A beautiful sunset] [🖼️ Image: Company Logo - 200x100] [🖼️ Clickable Image Banner]
⚠️ Important: Always use alt text!
The alt attribute is crucial for accessibility. Screen readers read it aloud for
visually impaired users. It also displays if the image fails to load. Never skip it!
9 Images
Images make web pages visually engaging. The <img> tag is self-closing and
requires a src (source) attribute for the image path.
<!-- Basic image --> <img src="images/photo.jpg" alt="Description of image"> <!-- Image with width and height --> <img src="logo.png" alt="Company Logo" width="200" height="100" > <!-- Image from URL --> <img src="https://example.com/image.jpg" alt="External image" > <!-- Figure with caption (semantic) --> <figure> <img src="chart.png" alt="Sales chart 2024"> <figcaption>Figure 1: Quarterly Sales Data</figcaption> </figure> <!-- Clickable image (link) --> <a href="https://example.com"> <img src="banner.jpg" alt="Click to visit"> </a> <!-- Responsive image --> <img src="photo.jpg" alt="Responsive image" style="max-width: 100%; height: auto;" >
💡 Image Best Practices
• Always include descriptive alt text
• Use width and height to prevent layout shift
• Compress images for faster loading
• Use WebP format for better compression
10 Tables
Tables display data in rows and columns. Use them for actual tabular data like schedules, statistics, or comparisons - not for page layout!
<table> <!-- Caption - table title --> <caption>Employee Directory</caption> <!-- Table header --> <thead> <tr> <th>Name</th> <th>Department</th> <th>Email</th> </tr> </thead> <!-- Table body --> <tbody> <tr> <td>Alice Smith</td> <td>Engineering</td> <td>alice@company.com</td> </tr> <tr> <td>Bob Johnson</td> <td>Marketing</td> <td>bob@company.com</td> </tr> </tbody> <!-- Table footer (optional) --> <tfoot> <tr> <td colspan="3">Total: 2 employees</td> </tr> </tfoot> </table>
| Name | Department | |
|---|---|---|
| Alice Smith | Engineering | alice@company.com |
| Bob Johnson | Marketing | bob@company.com |
11 Forms
Forms collect user input - login credentials, search queries, contact messages, etc.
The <form> element wraps input fields and defines where data goes when submitted.
<!-- form: action = where to send data, method = how to send --> <form action="/submit" method="POST"> <!-- Text input with label --> <!-- 'for' attribute links label to input by 'id' --> <label for="username">Username:</label> <input type="text" id="username" name="username" placeholder="Enter your username" required > <!-- Email input - validates email format --> <label for="email">Email:</label> <input type="email" id="email" name="email" placeholder="you@example.com" required > <!-- Password input - hides characters --> <label for="password">Password:</label> <input type="password" id="password" name="password" minlength="8" required > <!-- Dropdown select --> <label for="country">Country:</label> <select id="country" name="country"> <option value="">Select a country</option> <option value="in">India</option> <option value="us">United States</option> <option value="uk">United Kingdom</option> </select> <!-- Textarea for multi-line text --> <label for="message">Message:</label> <textarea id="message" name="message" rows="4" placeholder="Type your message..." ></textarea> <!-- Checkbox --> <input type="checkbox" id="subscribe" name="subscribe"> <label for="subscribe">Subscribe to newsletter</label> <!-- Submit button --> <button type="submit">Submit</button> </form>
Username: [________________]
Email: [________________]
Password: [••••••••••••••••]
Country: [▼ Select a country]
Message: [________________]
[ ]
[________________]
☐ Subscribe to newsletter
[ Submit ]
12 Input Types
HTML5 introduced many new input types that provide built-in validation and better user experience, especially on mobile devices.
<!-- Text inputs --> <input type="text" placeholder="Regular text"> <input type="password" placeholder="Hidden text"> <input type="email" placeholder="Email validation"> <input type="url" placeholder="URL validation"> <input type="tel" placeholder="Phone keyboard"> <input type="search" placeholder="Search field"> <!-- Number inputs --> <input type="number" min="0" max="100" step="1"> <input type="range" min="0" max="100"> <!-- Date/Time inputs --> <input type="date"> <input type="time"> <input type="datetime-local"> <input type="month"> <input type="week"> <!-- Selection inputs --> <input type="checkbox"> Remember me <input type="radio" name="gender"> Male <input type="radio" name="gender"> Female <!-- Other inputs --> <input type="color"> <input type="file" accept="image/*"> <input type="hidden" name="token" value="abc123"> <!-- Buttons --> <input type="submit" value="Submit Form"> <input type="reset" value="Clear Form"> <button type="button">Click Me</button>
Input Types Reference
| Type | Purpose | Mobile Keyboard |
|---|---|---|
email | Email with @ validation | @ symbol shown |
tel | Phone numbers | Number pad |
url | Website URLs | .com button |
number | Numeric input with spinners | Number pad |
date | Date picker | Calendar picker |
color | Color picker | Color palette |
13 Semantic HTML
Semantic elements clearly describe their meaning to both browsers and developers.
Instead of generic <div> containers, use elements like <header>,
<nav>, <main>, <article>, and <footer>.
🔑 Why Semantic HTML Matters
Accessibility: Screen readers understand page structure
SEO: Search engines better understand content
Maintainability: Code is easier to read and modify
<!DOCTYPE html> <html lang="en"> <head> <title>Semantic HTML Example</title> </head> <body> <!-- Header: top of page, contains logo/nav --> <header> <h1>My Website</h1> <!-- Nav: navigation links --> <nav> <a href="/">Home</a> <a href="/about">About</a> <a href="/contact">Contact</a> </nav> </header> <!-- Main: primary content area --> <main> <!-- Article: self-contained content --> <article> <h2>Blog Post Title</h2> <p>Published on <time datetime="2025-01-27">January 27, 2025</time></p> <!-- Section: thematic grouping --> <section> <h3>Introduction</h3> <p>This is the introduction paragraph...</p> </section> <section> <h3>Main Content</h3> <p>This is the main content...</p> </section> </article> <!-- Aside: sidebar content --> <aside> <h3>Related Posts</h3> <ul> <li><a href="#">Another Post</a></li> </ul> </aside> </main> <!-- Footer: bottom of page --> <footer> <p>© 2025 My Website. All rights reserved.</p> </footer> </body> </html>
Semantic Elements Reference
| Element | Purpose |
|---|---|
<header> | Page or section header |
<nav> | Navigation links |
<main> | Main content (one per page) |
<article> | Self-contained content |
<section> | Thematic grouping |
<aside> | Sidebar content |
<footer> | Page or section footer |
<figure> | Image with caption |
<time> | Date/time |
8 Multimedia (Audio & Video)
HTML5 provides native support for audio and video without plugins. You can embed media files and control playback directly in the browser.
<!-- Basic video with controls --> <video controls width="640" height="360" poster="thumbnail.jpg" > <!-- Multiple sources for browser compatibility --> <source src="video.mp4" type="video/mp4"> <source src="video.webm" type="video/webm"> <!-- Fallback text --> Your browser doesn't support video. </video> <!-- Autoplay (muted required for autoplay) --> <video autoplay muted loop playsinline> <source src="background.mp4" type="video/mp4"> </video> <!-- YouTube Embed (iframe) --> <iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" title="Video title" allow="accelerometer; autoplay; clipboard-write" allowfullscreen ></iframe>
<!-- Basic audio player --> <audio controls> <source src="audio.mp3" type="audio/mpeg"> <source src="audio.ogg" type="audio/ogg"> Your browser doesn't support audio. </audio> <!-- Audio with all attributes --> <audio controls preload="metadata" <!-- none | metadata | auto --> loop <!-- repeat playback --> > <source src="podcast.mp3" type="audio/mpeg"> </audio>
Video/Audio Attributes
| Attribute | Purpose |
|---|---|
controls | Show play/pause, volume, etc. |
autoplay | Start playing automatically |
muted | Start muted (required for autoplay) |
loop | Repeat when finished |
poster | Thumbnail image (video only) |
preload | none | metadata | auto |
9 Accessibility (A11y)
Accessible websites work for everyone, including users with disabilities who use screen readers, keyboard navigation, or other assistive technologies. Good accessibility is also good SEO.
<!-- 1. Always add alt text to images --> <img src="chart.png" alt="Bar chart showing sales growth from 2020-2024" > <!-- Decorative images: empty alt --> <img src="decorative-border.png" alt=""> <!-- 2. Use proper heading hierarchy --> <h1>Page Title</h1> <!-- One h1 per page --> <h2>Section Title</h2> <!-- Don't skip levels --> <h3>Subsection</h3> <h2>Another Section</h2> <!-- 3. Label form inputs --> <label for="email">Email Address:</label> <input type="email" id="email" name="email" required aria-describedby="email-hint" > <span id="email-hint">We'll never share your email</span> <!-- 4. ARIA roles for custom elements --> <div role="button" tabindex="0" aria-pressed="false" > Toggle Setting </div> <!-- 5. Skip link for keyboard users --> <a href="#main-content" class="skip-link"> Skip to main content </a> <!-- 6. Lang attribute for screen readers --> <html lang="en"> <p lang="es">Hola mundo</p> <!-- 7. Accessible tables --> <table> <caption>Monthly Sales Data</caption> <thead> <tr> <th scope="col">Month</th> <th scope="col">Revenue</th> </tr> </thead> <tbody> <tr> <th scope="row">January</th> <td>$10,000</td> </tr> </tbody> </table>
💡 Quick A11y Checklist
✓ All images have alt text
✓ Headings are hierarchical (h1→h2→h3)
✓ All form inputs have labels
✓ Color contrast ratio is at least 4.5:1
✓ Site is navigable by keyboard (Tab key)
✓ Page has lang attribute
10 Meta Tags & SEO
Meta tags provide metadata about your webpage. They're crucial for SEO (Search Engine Optimization), social media sharing, and browser behavior.
<head> <!-- Character encoding --> <meta charset="UTF-8"> <!-- Responsive viewport --> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Page title (important for SEO!) --> <title>Learn HTML - Complete Tutorial | MyWebsite</title> <!-- Meta description (shown in search results) --> <meta name="description" content="Learn HTML from basics to advanced. Free tutorial covering tags, forms, semantic HTML, and accessibility." > <!-- Keywords (less important now, but still used) --> <meta name="keywords" content="HTML, tutorial, web development, forms"> <!-- Author --> <meta name="author" content="Your Name"> <!-- Open Graph (for Facebook/LinkedIn sharing) --> <meta property="og:title" content="Learn HTML - Complete Tutorial"> <meta property="og:description" content="Master HTML with our free comprehensive guide"> <meta property="og:image" content="https://example.com/images/og-image.jpg"> <meta property="og:url" content="https://example.com/html-tutorial"> <meta property="og:type" content="article"> <!-- Twitter Card --> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:title" content="Learn HTML - Complete Tutorial"> <meta name="twitter:description" content="Master HTML with our free guide"> <!-- Favicon --> <link rel="icon" href="/favicon.ico"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <!-- Canonical URL (prevents duplicate content) --> <link rel="canonical" href="https://example.com/html-tutorial"> <!-- Robots (indexing instructions) --> <meta name="robots" content="index, follow"> </head>
⚠️ SEO Tips
• Title should be 50-60 characters
• Description should be 150-160 characters
• Use unique titles and descriptions per page
• Include target keyword in title and description