Codcups
Progress: 0%

01. 🚀 HTML Basics & Program Structure

HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It describes the structure of web pages using markup. Think of HTML as the skeleton of a webpage - it provides the basic structure that CSS will style and JavaScript will make interactive.

Why HTML Matters

Every single website you visit is built with HTML. From simple blogs to complex web applications, HTML forms the foundation. Without HTML, web browsers wouldn't know how to display text, images, or links. It's the first language every web developer must learn.

The Basic HTML Document Structure

Every HTML document has a specific structure that browsers understand. This structure tells the browser how to interpret and display your content. The basic components are like the essential parts of a document:

  • DOCTYPE Declaration: <!DOCTYPE html> tells the browser this is an HTML5 document. This is the very first line and it's not an HTML tag - it's an instruction to the browser.
  • HTML Element: <html> is the root element of an HTML page. All other elements are contained within this element.
  • Head Section: <head> contains meta information about the document that isn't displayed on the page, like the title, character set, and links to CSS files.
  • Body Section: <body> contains the visible page content - everything users see and interact with.

The DOCTYPE declaration must be the very first thing in your HTML document, before the <html> tag. If you forget it, browsers might render your page in "quirks mode" which can lead to inconsistent display.

Example: Basic HTML Template

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>My First Web Page</title>
    </head>
    <body>
        <h1>Welcome to HTML!</h1>
        <p>This is my first web page.</p>
    </body>
    </html>

Note: The lang="en" attribute specifies the language of the document. This is important for accessibility tools like screen readers and for search engines. The viewport meta tag makes your page responsive on mobile devices.

Understanding the Meta Tags

The charset="UTF-8" specifies the character encoding. UTF-8 includes most characters from all human languages, so it's essential for international websites. The viewport tag controls how the page is displayed on mobile devices - width=device-width makes the page width match the screen width, and initial-scale=1.0 sets the initial zoom level to 100%.

Live Preview:

Welcome to HTML!

This is my first web page. Notice how the heading is larger and bolder - that's because it's an <h1> element, which browsers style differently from regular paragraph text.

02. 📦 HTML Tags & Elements

HTML elements are the building blocks of HTML pages. They consist of tags and content. An HTML element is defined by a start tag, some content, and an end tag. Tags are the names enclosed in angle brackets, like <p> for paragraph.

Anatomy of an HTML Element

Let's break down a simple element: <p>This is a paragraph.</p>
- <p> is the opening tag
- "This is a paragraph." is the content
- </p> is the closing tag (note the forward slash)
Together, these three parts form a complete HTML element.

Common HTML Elements

Here are the most frequently used HTML elements that you'll encounter in almost every web page:

  • Headings: <h1> to <h6> for titles and subtitles. <h1> is the most important (and largest), while <h6> is the least important.
  • Paragraphs: <p> for text content. This is where you put the main body text of your page.
  • Divisions: <div> for grouping elements. It's a generic container that has no semantic meaning.
  • Spans: <span> for inline grouping. Unlike div, span doesn't create a new line.
  • Line Breaks: <br> for new lines. This is a void element (no closing tag).
  • Horizontal Rules: <hr> for thematic breaks. Creates a horizontal line across the page.

Block vs Inline Elements

HTML elements can be either block-level or inline. Block-level elements (like <div>, <p>, <h1>) start on a new line and take up the full width available. Inline elements (like <span>, <a>, <strong>) do not start on a new line and only take up as much width as necessary.

Some HTML elements are "void" or "self-closing" elements that don't have closing tags. Examples include <br>, <img>, <hr>, and <input>. In HTML5, you can write them as <br> or <br/>.

Example: Various HTML Elements

    <h1>Main Heading</h1>
    <h2>Subheading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph with a <br>line break.</p>
    <hr>
    <div>
        <span>This is inline</span>
        <span>text in a div.</span>
    </div>

Understanding the Example

In this example, notice how:
1. The <h1> and <h2> create headings of different sizes
2. The <br> tag forces text after it to appear on a new line within the same paragraph
3. The <hr> creates a visible horizontal line
4. The <div> groups the two <span> elements together
5. The <span> elements display inline (side by side) because they're inline elements

03. ✍️ Text Formatting in HTML

HTML provides various elements for text formatting and styling. While CSS is now the preferred method for styling, these HTML formatting elements are still widely used for semantic purposes and quick formatting.

Semantic vs Presentational Formatting

Some formatting tags carry semantic meaning beyond just appearance. For example, <strong> indicates importance, while <b> just makes text bold. Screen readers may emphasize <strong> text more strongly than <b> text.

Here are the essential text formatting elements:

  • Bold: <b> or <strong> - <b> is for stylistic bold, while <strong> indicates strong importance.
  • Italic: <i> or <em> - <i> is for stylistic italic, while <em> indicates emphasis.
  • Underline: <u> - Generally avoided in modern web design as users expect underlined text to be a link.
  • Strikethrough: <s> or <del> - <s> indicates content no longer accurate, <del> indicates deleted text.
  • Superscript: <sup> - Raises text above the baseline, used for exponents and footnotes.
  • Subscript: <sub> - Lowers text below the baseline, used for chemical formulas.
  • Highlight: <mark> - Highlights text for reference or notation.
  • Small text: <small> - Represents side comments or fine print.

When to Use Which Tag?

Use <strong> when the text is important (like warnings). Use <em> when you want to emphasize a word (like in dialogue). Use <mark> to highlight search terms or important parts. The choice depends on meaning, not just appearance.

Remember: HTML is for structure and meaning, CSS is for presentation. While these tags do affect appearance, their primary purpose is to convey meaning. Use CSS when you only want to change how something looks.

Example: Text Formatting

    <p>This is <b>bold</b> text.</p>
    <p>This is <strong>important</strong> text.</p>
    <p>This is <i>italic</i> text.</p>
    <p>This is <em>emphasized</em> text.</p>
    <p>This is <u>underlined</u> text.</p>
    <p>This is <s>strikethrough</s> text.</p>
    <p>H<sub>2</sub>O is water.</p>
    <p>10<sup>2</sup> = 100</p>
    <p>This is <mark>highlighted</mark> text.</p>
    <p>This is <small>smaller</small> text.</p>

Practical Applications

Here's where you'd typically use these formatting elements:
- <sub> and <sup>: Scientific formulas, mathematical equations, footnote references
- <mark>: Search results, important notes, key terms
- <small>: Legal disclaimers, copyright information, secondary information
- <del> and <ins>: Showing changes in documents or pricing

Live Preview:

This is bold text.

This is important text.

This is italic text.

This is emphasized text.

This is underlined text.

This is strikethrough text.

H2O is water.

102 = 100

This is highlighted text.

This is smaller text.

04. 📋 Lists in HTML

Lists are essential for organizing content in a structured way. HTML provides three types of lists, each serving different purposes for content organization.

Why Lists Matter

Lists improve readability by breaking down complex information into digestible chunks. They help users scan content quickly, which is especially important in today's fast-paced web browsing. Lists also improve SEO as search engines can better understand structured content.

HTML provides three types of lists:

  • Unordered Lists: Bulleted lists using <ul> - Use when items have no particular order.
  • Ordered Lists: Numbered lists using <ol> - Use when sequence matters (steps, rankings).
  • Description Lists: Definition lists using <dl> - Use for terms and definitions.

Nested Lists

You can create nested lists (lists within lists) by placing a <ul>, <ol>, or <dl> inside an <li> element. This creates hierarchical structures like outlines or multi-level menus.

List Attributes

Lists can be customized with various attributes:

  • type - Type of numbering/bullets (1, A, a, I, i for ordered; disc, circle, square for unordered)
  • start - Starting number (for ordered lists) - e.g., start="3" begins at 3
  • reversed - Reverse numbering (counts down instead of up)

For unordered lists, you should use CSS (list-style-type property) instead of the type attribute for styling bullets, as the type attribute is deprecated in HTML5.

Example: Different Types of Lists

    <!-- Unordered List -->
    <ul>
        <li>Coffee</li>
        <li>Tea</li>
        <li>Milk</li>
    </ul>

    <!-- Ordered List -->
    <ol>
        <li>First item</li>
        <li>Second item</li>
        <li>Third item</li>
    </ol>

    <!-- Description List -->
    <dl>
        <dt>HTML</dt>
        <dd>HyperText Markup Language</dd>
        <dt>CSS</dt>
        <dd>Cascading Style Sheets</dd>
    </dl>

When to Use Each List Type

Unordered lists are perfect for: navigation menus, feature lists, bullet points in presentations.
Ordered lists work best for: step-by-step instructions, rankings, numbered procedures.
Description lists are ideal for: glossaries, FAQs, metadata display, key-value pairs.

Live Preview:

Unordered List

  • Coffee
  • Tea
  • Milk

Ordered List

  1. First item
  2. Second item
  3. Third item

Description List

HTML
HyperText Markup Language
CSS
Cascading Style Sheets

06. 📊 HTML Tables

Tables are used to display data in rows and columns. While they were once misused for page layout, in modern web development tables should only be used for tabular data - information that logically belongs in a grid format.

When to Use Tables

Use tables for: financial data, schedules, comparisons, statistics, calendars, pricing grids, and any data that has a clear row-column relationship. Avoid using tables for page layout - use CSS Flexbox or Grid instead for layout purposes.

Table Structure

A well-structured table uses several elements to organize data semantically:

  • <table> - Defines the table container. All table elements go inside this.
  • <tr> - Table row. Creates a horizontal row of cells.
  • <th> - Table header cell. Used for column or row headers. Browsers typically display these in bold.
  • <td> - Table data cell. Contains the actual data.
  • <thead> - Groups header content. Contains <tr> elements with <th> cells.
  • <tbody> - Groups body content. Contains the main data rows.
  • <tfoot> - Groups footer content. For summaries or totals.
  • <caption> - Provides a title or description for the table.

Accessibility Considerations

For accessible tables:
1. Use <th> with scope="col" or scope="row" attributes
2. Provide a <caption> for table description
3. Use <thead>, <tbody>, and <tfoot> for structure
4. For complex tables, use headers attribute to associate data cells with their headers

Table Attributes

While many table attributes are deprecated in HTML5 (use CSS instead), these are still relevant:

  • colspan - Cell spans multiple columns. Example: colspan="2"
  • rowspan - Cell spans multiple rows. Example: rowspan="3"
  • scope - Defines whether header applies to row, column, or group
  • headers - Associates data cells with header cells (for complex tables)

Never use tables for page layout! This was common in the 1990s but is now considered bad practice. Tables for layout create accessibility issues, are hard to maintain, and don't work well on mobile devices.

Example: Basic HTML Table

    <table>
        <caption>Employee Information</caption>
        <thead>
            <tr>
                <th scope="col">Name</th>
                <th scope="col">Age</th>
                <th scope="col">City</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>John Doe</td>
                <td>25</td>
                <td>New York</td>
            </tr>
            <tr>
                <td>Jane Smith</td>
                <td>30</td>
                <td>London</td>
            </tr>
        </tbody>
    </table>

Advanced Table Features

For complex data tables:
1. Use colspan and rowspan for merged cells
2. Group columns with <colgroup> and <col>
3. Use the headers attribute to associate data cells with multiple headers
4. Consider breaking very large tables into multiple smaller tables

Live Preview:
Name Age City
John Doe 25 New York
Jane Smith 30 London

Note: This table has basic styling for demonstration. In practice, use CSS for table styling.

07. 📝 HTML Forms

Forms are used to collect user input and submit it to a server for processing. They're essential for interactive websites - login forms, contact forms, search boxes, registration forms, and checkout processes all use HTML forms.

The Form Submission Process

When a user submits a form: 1) Browser collects all form data, 2) Data is sent to the server (URL in action attribute), 3) Server processes the data (using PHP, Node.js, Python, etc.), 4) Server sends a response back to the browser. The method attribute determines how data is sent: GET (visible in URL) or POST (hidden in request body).

Form Elements

Forms consist of various input elements, each serving a specific purpose:

  • <form> - Container for form elements. Has action (where to send data) and method (GET or POST) attributes.
  • <input> - Various input types. The most versatile form element.
  • <textarea> - Multi-line text input. For comments, descriptions, long text.
  • <select> - Dropdown list. For selecting from multiple options.
  • <option> - Option in dropdown. Goes inside <select>.
  • <button> - Clickable button. Can be type="submit", "reset", or "button".
  • <label> - Label for form elements. Improves accessibility and usability.
  • <fieldset> - Groups related form elements. Often with <legend>.
  • <legend> - Caption for <fieldset>.

Form Accessibility

Always use <label> elements with the for attribute matching the input's id. This:
1. Makes forms usable with screen readers
2. Allows clicking the label to focus the input
3. Improves touch target size on mobile devices
4. Helps users understand what each field is for

Input Types

HTML5 introduced many new input types that provide better user experience and validation:

  • Basic: text, password, email, tel
  • Numbers & Dates: number, date, time, datetime-local, month, week
  • Choices: checkbox, radio, range (slider)
  • Files & Buttons: file, submit, reset, button, image
  • Specialized: color, search, url, hidden

Form Validation Attributes

HTML5 provides built-in validation without JavaScript:
- required: Field must be filled
- min/max: Minimum/maximum values
- minlength/maxlength: Text length limits
- pattern: Regular expression validation
- step: Increment for number inputs

Always validate form data on the server-side too! Client-side validation (HTML/JavaScript) improves user experience but can be bypassed. Server-side validation is essential for security.

Example: Registration Form

<form action="/submit" method="POST">
    <fieldset>
        <legend>Personal Information</legend>
        
        <label for="name">Full Name:</label>
        <input type="text" id="name" name="name" required 
               placeholder="Enter your full name">
        
        <label for="email">Email Address:</label>
        <input type="email" id="email" name="email" required 
               placeholder="you@example.com">
        
        <label for="password">Password:</label>
        <input type="password" id="password" name="password" 
               minlength="8" required>
        
        <label>Gender:</label>
        <div>
            <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>
            
            <input type="radio" id="other" name="gender" value="other">
            <label for="other">Other</label>
        </div>
    </fieldset>
    
    <fieldset>
        <legend>Additional Information</legend>
        
        <label for="country">Country:</label>
        <select id="country" name="country">
            <option value="">Select a country</option>
            <option value="us">United States</option>
            <option value="uk">United Kingdom</option>
            <option value="ca">Canada</option>
        </select>
        
        <label for="bio">Biography:</label>
        <textarea id="bio" name="bio" rows="4" 
                  placeholder="Tell us about yourself..."></textarea>
        
        <label>
            <input type="checkbox" name="newsletter" checked>
            Subscribe to newsletter
        </label>
    </fieldset>
    
    <button type="submit">Register</button>
    <button type="reset">Clear Form</button>
</form>

Form Security Considerations

1. Always use HTTPS for forms transmitting sensitive data
2. Implement CSRF (Cross-Site Request Forgery) tokens
3. Sanitize and validate ALL user input on the server
4. Use prepared statements for database queries
5. Hash passwords with strong algorithms (bcrypt, Argon2)
6. Implement rate limiting to prevent brute force attacks

Live Preview:

Form Preview: This would display a fully functional form with all the elements shown in the code example.

The form would include text inputs, email validation, password field, radio buttons, dropdown select, textarea, checkboxes, and submit/reset buttons.

Try it: Copy the code into the Online Code Editor to see the actual form in action!

08. 🏗️ Semantic HTML5

Semantic HTML elements clearly describe their meaning to both browser and developer. Unlike generic elements like <div> and <span>, semantic elements tell you what type of content they contain.

The Semantic Web Vision

Semantic HTML is part of the larger "Semantic Web" vision where data on the web is structured in a way that machines can understand it. By using semantic elements, you're not just making your code more readable for humans - you're also helping search engines, screen readers, and other automated tools understand your content structure.

Common Semantic Elements

HTML5 introduced several new semantic elements that replace the generic <div> elements we used to use for layout:

  • <header> - Introductory content or navigational aids. Typically contains logo, heading, navigation.
  • <nav> - Navigation links. For major navigation blocks (not every link group).
  • <main> - Main content of the document. Should be unique to the document.
  • <article> - Independent, self-contained content. Should make sense on its own.
  • <section> - Thematic grouping of content. Usually with a heading.
  • <aside> - Sidebar content. Related to main content but separate.
  • <footer> - Footer content. Typically contains authorship, copyright, contact.
  • <figure> & <figcaption> - Self-contained media with caption.
  • <time> - Date/time. Can include datetime attribute for machine-readable format.
  • <mark> - Highlighted text for reference purposes.

Choosing Between Article and Section

Use <article> when the content could be syndicated (RSS feed) or reused independently. Use <section> for thematic grouping within an article or page. A good test: Ask "Could this be a separate blog post?" If yes, use <article>.

Document Outline Algorithm

Semantic elements create an implicit document outline that helps assistive technologies understand page structure. Headings (<h1>-<h6>) within semantic elements create this outline. Each <article>, <section>, <aside>, and <nav> creates a new section in the outline.

Semantic HTML improves accessibility, SEO, and code readability. Search engines give semantic pages higher rankings, screen readers provide better navigation, and developers can understand code faster.

Example: Semantic Layout

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Blog Post - Semantic Example</title>
</head>
<body>
    <header>
        <h1>My Blog</h1>
        <nav>
            <ul>
                <li><a href="/">Home</a></li>
                <li><a href="/about">About</a></li>
                <li><a href="/contact">Contact</a></li>
            </ul>
        </nav>
    </header>

    <main>
        <article>
            <header>
                <h2>Understanding Semantic HTML</h2>
                <p>Published on <time datetime="2024-03-15">March 15, 2024</time></p>
            </header>
            
            <section>
                <h3>What is Semantic HTML?</h3>
                <p>Semantic HTML means using HTML elements according to their meaning...</p>
                <figure>
                    <img src="semantic-html.jpg" alt="Diagram showing semantic HTML structure">
                    <figcaption>Semantic HTML document structure</figcaption>
                </figure>
            </section>
            
            <section>
                <h3>Benefits of Semantic HTML</h3>
                <p>The main benefits are improved accessibility and SEO...</p>
            </section>
        </article>
        
        <aside>
            <h3>Related Articles</h3>
            <ul>
                <li><a href="#">HTML5 New Features</a></li>
                <li><a href="#">Web Accessibility Guide</a></li>
            </ul>
        </aside>
    </main>

    <footer>
        <p>© 2024 My Blog. All rights reserved.</p>
        <address>Contact: <a href="mailto:author@example.com">author@example.com</a></address>
    </footer>
</body>
</html>

Accessibility Benefits

Screen readers use semantic elements to:
1. Announce when users enter/leave landmark regions (header, main, footer, etc.)
2. Provide keyboard navigation between landmarks
3. Understand the document structure for better content presentation
4. Identify the main content area vs navigation vs supplementary content

Live Preview:
<header> - Would contain site header here
<main> - Would contain main content here
<article> - Blog post content
<aside> - Sidebar with related content
<footer> - Would contain footer content here

Each colored box represents a different semantic element. Notice how the structure is clear even without seeing the actual content.

09. 🎵 Multimedia in HTML

HTML5 introduced native support for audio and video without plugins like Flash. This was a major advancement that improved performance, security, and accessibility of multimedia content on the web.

The End of Flash

Before HTML5, multimedia required browser plugins (mainly Adobe Flash). Flash had security vulnerabilities, poor performance on mobile devices, and accessibility issues. HTML5 <audio> and <video> elements provide a standardized, secure, and accessible way to include multimedia.

Audio Element

The <audio> element embeds sound content. It can contain multiple <source> elements for different formats (browsers use the first supported format). Key attributes:

  • controls - Shows audio controls (play/pause, volume, etc.)
  • autoplay - Starts playing automatically (use sparingly - can be annoying)
  • loop - Repeats audio when it ends
  • muted - Starts muted (useful for autoplay videos)
  • preload - How to preload the audio: none, metadata, or auto
  • src - Source file (can also use <source> elements inside)

Audio Format Considerations

Provide multiple formats for cross-browser compatibility:
- MP3: Widely supported, good compression
- OGG: Open format, good for Firefox
- WAV: Uncompressed, high quality but large files
- WebM: Open format, good compression
Always include fallback content for browsers that don't support the audio element.

Video Element

The <video> element embeds video content. It shares many attributes with <audio> but adds visual-specific attributes:

  • width & height - Video dimensions in pixels
  • poster - Thumbnail image shown before video plays
  • autoplay, loop, muted - Same as audio element
  • controls - Shows video controls
  • playsinline - Prevents fullscreen on iOS (for inline playback)
  • preload - Same as audio: none, metadata, or auto

Video Optimization

Video files are large - optimize them!
1. Compress videos (HandBrake, FFmpeg)
2. Use modern codecs (H.264, VP9, AV1)
3. Provide multiple resolutions (adaptive streaming)
4. Use CDN for delivery
5. Implement lazy loading
6. Consider using video hosting services (YouTube, Vimeo) for large files

Responsive Multimedia

For responsive design, don't use fixed width and height attributes. Instead, use CSS:
video { max-width: 100%; height: auto; }
This makes videos scale with their container while maintaining aspect ratio.

Always include captions/subtitles for videos! Use the <track> element with kind="captions" for accessibility. This helps hearing-impaired users and people watching without sound.

Example: Audio and Video

<!-- Audio Player with Multiple Sources -->
<audio controls>
    <source src="audio/sound.mp3" type="audio/mpeg">
    <source src="audio/sound.ogg" type="audio/ogg">
    <source src="audio/sound.webm" type="audio/webm">
    Your browser does not support the audio element.
    <a href="audio/sound.mp3">Download the audio</a>
</audio>

<!-- Video Player with Captions -->
<video controls width="640" poster="video-poster.jpg">
    <source src="video/movie.mp4" type="video/mp4">
    <source src="video/movie.webm" type="video/webm">
    
    <track src="captions/en.vtt" kind="captions" 
           srclang="en" label="English">
    <track src="captions/es.vtt" kind="captions" 
           srclang="es" label="Spanish" default>
    
    Your browser does not support the video element.
    <a href="video/movie.mp4">Download the video</a>
</video>

<!-- Responsive Video with CSS -->
<div class="video-container">
    <video controls poster="poster.jpg">
        <source src="video.mp4" type="video/mp4">
    </video>
</div>

<!-- Embed YouTube Video -->
<iframe width="560" height="315" 
        src="https://www.youtube.com/embed/dQw4w9WgXcQ" 
        title="YouTube video player" 
        frameborder="0" 
        allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" 
        allowfullscreen>
</iframe>

WebVTT Caption Format

WebVTT (.vtt files) is the standard for video captions. A simple VTT file looks like:
WEBVTT
00:00:01.000 --> 00:00:04.000
Hello world!
00:00:05.000 --> 00:00:08.000
This is a caption example.
You can create VTT files with tools or manually. Always test captions for timing accuracy.

Live Preview:

Audio Player

Controls would appear here: Play/Pause, Volume, Progress Bar, Time Display

The browser's native audio controls would render based on the user's operating system.

Video Player

Video preview with poster image

Controls: Play, Fullscreen, Volume, Settings, Captions

Note: Actual multimedia requires real media files. Try the code in the Online Code Editor with your own audio/video files!

10. ⚡ Advanced HTML5 Features

HTML5 introduced many advanced features and APIs that enable rich web applications. These features reduce reliance on plugins and JavaScript for common tasks, improving performance and security.

The HTML5 Revolution

HTML5 wasn't just about new elements - it was a comprehensive platform for web applications. It included:
1. New semantic elements
2. Native multimedia support
3. Advanced form controls
4. Canvas for graphics
5. Local storage
6. Geolocation API
7. Web Workers for threading
8. Web Sockets for real-time communication
This transformed the web from documents to applications.

HTML5 APIs

HTML5 includes JavaScript APIs that work with HTML elements to create interactive experiences:

  • Canvas API: For drawing graphics, animations, games. Creates a bitmap drawing surface.
  • Geolocation API: For location data (with user permission). Used for maps, local services.
  • Local Storage: For storing data locally in browser. localStorage and sessionStorage.
  • Drag & Drop API: For drag-and-drop functionality. Native browser support.
  • Web Workers: For background processing. Runs scripts in background threads.
  • Web Sockets: For real-time communication. Two-way persistent connection.
  • History API: For manipulating browser history. Enables single-page applications.
  • File API: For reading files locally. Enables file uploads with previews.

Progressive Web Apps (PWAs)

HTML5 features enable Progressive Web Apps - web apps that feel like native apps:
1. Service Workers for offline functionality
2. Web App Manifest for home screen installation
3. Push Notifications for user engagement
4. Cache API for resource caching
PWAs work across all devices with a single codebase.

New Input Types

HTML5 introduced specialized input types that provide better user experience and built-in validation:

  • color - Color picker. Returns hex color value.
  • date, time, datetime-local - Date/time pickers.
  • range - Slider control. min, max, step attributes.
  • search - Search field. May have clear button.
  • tel - Telephone number. Mobile devices may show phone pad.
  • url - URL field. Validates URL format.
  • number - Number input. Spinner controls, validation.
  • email - Email input. Validates email format (basic).
  • month, week - Month/week selectors.

Fallback for New Input Types

Browsers that don't support new input types fall back to type="text". Always:
1. Provide labels and instructions
2. Use JavaScript polyfills if needed
3. Implement server-side validation (never rely only on client-side)
4. Test across different browsers and devices

New Elements

HTML5 also introduced new elements beyond semantic ones:

  • <progress> - Progress bar. Shows completion percentage.
  • <meter> - Meter/gauge. Shows scalar measurement.
  • <details> & <summary> - Expandable widget.
  • <datalist> - Predefined options for input. Creates autocomplete.
  • <output> - Calculation results. For form calculations.
  • <template> - Client-side template. Content not rendered initially.

HTML5 is a living standard! New features are regularly added. Check the WHATWG HTML Living Standard for the latest specifications and browser compatibility.

Example: Advanced HTML5 Features

<!-- Canvas Drawing -->
<canvas id="myCanvas" width="200" height="100">
    Your browser doesn't support canvas.
</canvas>
<script>
    const canvas = document.getElementById('myCanvas');
    const ctx = canvas.getContext('2d');
    ctx.fillStyle = 'blue';
    ctx.fillRect(10, 10, 150, 80);
</script>

<!-- New Input Types -->
<input type="color" value="#ff0000">
<input type="date" min="2024-01-01" max="2024-12-31">
<input type="range" min="0" max="100" value="50" step="10">
<input type="search" placeholder="Search...">
<input type="email" multiple placeholder="Enter email(s)">

<!-- Progress and Meter -->
<label>Upload Progress:</label>
<progress value="75" max="100">75%</progress>

<label>Storage Usage:</label>
<meter value="0.6" min="0" max="1" low="0.25" high="0.75" optimum="0.5">
    60% used
</meter>

<!-- Details & Summary (Accordion) -->
<details>
    <summary>Click to expand for more information</summary>
    <p>This content is hidden by default but shown when expanded.</p>
</details>

<!-- Datalist for Autocomplete -->
<label for="browser">Choose a browser:</label>
<input list="browsers" id="browser" name="browser">
<datalist id="browsers">
    <option value="Chrome">
    <option value="Firefox">
    <option value="Safari">
</datalist>

<!-- Output Element -->
<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
    <input type="range" id="a" value="50"> +
    <input type="number" id="b" value="25"> =
    <output name="result" for="a b">75</output>
</form>

Canvas vs SVG

Canvas is bitmap-based: Good for games, image manipulation, pixel-based operations. You manipulate pixels. Once drawn, shapes are forgotten.
SVG is vector-based: Good for icons, logos, scalable graphics. You manipulate shapes as objects. Shapes remain in DOM, can be styled with CSS.
Choose Canvas for performance-intensive graphics, SVG for resolution-independent graphics.

Live Preview:

New Input Types

Progress & Meter

75% complete
60% used (in optimal range)

Details & Summary

Click to expand for more information

This content is hidden by default but shown when expanded. This creates an accordion effect without JavaScript!

Canvas Example

Canvas Drawing Area

This would be a blue rectangle drawn with Canvas API

These are visual representations. Copy the code to see actual functionality!