1. Home
  2. Coding Hub
  3. Coding Notes
  4. Html
  5. Audio Video
45% OFFBLACK FRIDAY SALE
Sale ends in
02Days
16Hrs
26Mins
18Secs
Claim
  1. Home
  2. Coding Hub
  3. Coding Notes
  4. Html
  5. Audio Video

Limited time offer

45% OFF

BLACK FRIDAY SALE

Sale ends in

02Days
16Hrs
26Mins
18Secs
Claim
HTMLCSSJavaScriptPythonJavaC++React.jsSQLNext.jsNode.js
Underrated CoderUnderrated Coder
Underrated CoderUnderrated Coder
Resources
  • Coding Hub
  • Roadmap
  • DSA Sheet
  • Coding Notes
  • Coding Quiz
  • Code Compiler
  • Coder AI
Interview Preparation
  • 1:1 Mentorship
  • Interview Q&A
Community
  • Blog
  • Coder Community
Help & Support
  • Contact Us
  • Troubleshooting
  • Report a Bug
HTMLCSSJavaScriptPythonJavaC++React.jsSQLNext.jsNode.js
Outline
HTML IntroductionDOM ParsingDocument StructureMetadata & <head>Viewport SetupLinks & FaviconsScript Loading
Heading HierarchyText SemanticsBlock vs InlineHyperlinks & AnchorsHTML ListsSemantic LayoutSectioning Elements
Image OptimizationResponsive <picture>Audio & VideoMedia <track>Inline SVG<iframe> Sandboxing
Table BasicsTable SemanticsSpanning & Captions
Form ArchitectureText InputsSelection ControlsSpecialized InputsLabels & Fieldsets<datalist> AutocompleteNative ValidationForm Submission
<details> Accordions<dialog> ModalsPopover APIInvoker Commands<template> Tag
data-* AttributesWeb AccessibilityARIA EssentialsOpen Graph SEOResource Hints
HTML

Audio & Video

Overview

Before HTML5, embedding video required clunky, insecure third-party plugins like Adobe Flash. Now, HTML provides native <audio> and <video> tags that are universally supported across all devices. They provide built-in, accessible playback controls, support multiple source formats to ensure cross-browser compatibility, and can be seamlessly manipulated using JavaScript's native Media API.

Syntax

html
<!-- Standard Video Embed -->
<video width="800" height="450" controls poster="/images/video-thumbnail.jpg">
  <!-- Provide multiple formats for cross-browser support -->
  <source src="tutorial.mp4" type="video/mp4">
  <source src="tutorial.webm" type="video/webm">
  
  <!-- Fallback text for ancient browsers -->
  Your browser does not support the video tag.
</video>

<!-- Standard Audio Embed -->
<audio controls>
  <source src="podcast-episode.mp3" type="audio/mpeg">
  <source src="podcast-episode.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>

Common Pitfalls

  • Using autoplay without muted. Modern browsers strictly block auto-playing videos that have sound to prevent annoying the user. If you want a video to autoplay (like a background video banner), you MUST include both autoplay and muted.
  • Forgetting the controls attribute. If you don't include it, the video will appear on the screen, but the user will have absolutely no play/pause buttons or volume slider to interact with it.

Interview Questions

What is the purpose of the poster attribute on a <video> tag?

It specifies an image to be shown while the video is downloading, or until the user hits the play button. Without it, the browser displays a blank black box or the first frame of the video, which might be awkwardly blurry.

Real-World Example

Creating a silent, looping, autoplaying background video for a sleek modern hero section.

example
html
<!-- 
  Plays automatically, loops infinitely, has no sound, 
  and plays inline on iOS without taking over the screen.
-->
<video 
  class="hero-background" 
  autoplay 
  loop 
  muted 
  playsinline
>
  <source src="/assets/hero-bg.mp4" type="video/mp4">
</video>

Check Your Knowledge

Test your understanding of Audio & Video with these quick questions.

Question 1

Why is it best practice to include multiple `<source>` tags inside a `<video>` element?

Take HTML Quiz
Outline
HTML IntroductionDOM ParsingDocument StructureMetadata & <head>Viewport SetupLinks & FaviconsScript Loading
Heading HierarchyText SemanticsBlock vs InlineHyperlinks & AnchorsHTML ListsSemantic LayoutSectioning Elements
Image OptimizationResponsive <picture>Audio & VideoMedia <track>Inline SVG<iframe> Sandboxing
Table BasicsTable SemanticsSpanning & Captions
Form ArchitectureText InputsSelection ControlsSpecialized InputsLabels & Fieldsets<datalist> AutocompleteNative ValidationForm Submission
<details> Accordions<dialog> ModalsPopover APIInvoker Commands<template> Tag
data-* AttributesWeb AccessibilityARIA EssentialsOpen Graph SEOResource Hints
HTML

Audio & Video

Overview

Before HTML5, embedding video required clunky, insecure third-party plugins like Adobe Flash. Now, HTML provides native <audio> and <video> tags that are universally supported across all devices. They provide built-in, accessible playback controls, support multiple source formats to ensure cross-browser compatibility, and can be seamlessly manipulated using JavaScript's native Media API.

Syntax

html
<!-- Standard Video Embed -->
<video width="800" height="450" controls poster="/images/video-thumbnail.jpg">
  <!-- Provide multiple formats for cross-browser support -->
  <source src="tutorial.mp4" type="video/mp4">
  <source src="tutorial.webm" type="video/webm">
  
  <!-- Fallback text for ancient browsers -->
  Your browser does not support the video tag.
</video>

<!-- Standard Audio Embed -->
<audio controls>
  <source src="podcast-episode.mp3" type="audio/mpeg">
  <source src="podcast-episode.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>

Common Pitfalls

  • Using autoplay without muted. Modern browsers strictly block auto-playing videos that have sound to prevent annoying the user. If you want a video to autoplay (like a background video banner), you MUST include both autoplay and muted.
  • Forgetting the controls attribute. If you don't include it, the video will appear on the screen, but the user will have absolutely no play/pause buttons or volume slider to interact with it.

Interview Questions

What is the purpose of the poster attribute on a <video> tag?

It specifies an image to be shown while the video is downloading, or until the user hits the play button. Without it, the browser displays a blank black box or the first frame of the video, which might be awkwardly blurry.

Real-World Example

Creating a silent, looping, autoplaying background video for a sleek modern hero section.

example
html
<!-- 
  Plays automatically, loops infinitely, has no sound, 
  and plays inline on iOS without taking over the screen.
-->
<video 
  class="hero-background" 
  autoplay 
  loop 
  muted 
  playsinline
>
  <source src="/assets/hero-bg.mp4" type="video/mp4">
</video>

Check Your Knowledge

Test your understanding of Audio & Video with these quick questions.

Question 1

Why is it best practice to include multiple `<source>` tags inside a `<video>` element?

Take HTML Quiz

HTML coding notes for Indian students — 41 topics with syntax, pitfalls, interview Q&A, and inline quizzes.

Topics in HTML

  1. HTML Introduction
  2. DOM Parsing
  3. Document Structure
  4. Metadata & <head>
  5. Viewport Setup
  6. Links & Favicons
  7. Script Loading
  8. Heading Hierarchy
  9. Text Semantics
  10. Block vs Inline
  11. Hyperlinks & Anchors
  12. HTML Lists
  13. Semantic Layout
  14. Sectioning Elements
  15. Image Optimization
  16. Responsive <picture>
  17. Audio & Video
  18. Media <track>
  19. Inline SVG
  20. <iframe> Sandboxing
  21. Table Basics
  22. Table Semantics
  23. Spanning & Captions
  24. Form Architecture
  25. Text Inputs
  26. Selection Controls
  27. Specialized Inputs
  28. Labels & Fieldsets
  29. <datalist> Autocomplete
  30. Native Validation
  31. Form Submission
  32. <details> Accordions
  33. <dialog> Modals
  34. Popover API
  35. Invoker Commands
  36. <template> Tag
  37. data-* Attributes
  38. Web Accessibility
  39. ARIA Essentials
  40. Open Graph SEO
  41. Resource Hints

Study next

  • All coding notes
  • HTML notes home
  • HTML certification quiz
  • Online compiler
  • Interview Q&A

HTML coding notes for Indian students — 41 topics with syntax, pitfalls, interview Q&A, and inline quizzes.

Topics in HTML

  1. HTML Introduction
  2. DOM Parsing
  3. Document Structure
  4. Metadata & <head>
  5. Viewport Setup
  6. Links & Favicons
  7. Script Loading
  8. Heading Hierarchy
  9. Text Semantics
  10. Block vs Inline
  11. Hyperlinks & Anchors
  12. HTML Lists
  13. Semantic Layout
  14. Sectioning Elements
  15. Image Optimization
  16. Responsive <picture>
  17. Audio & Video
  18. Media <track>
  19. Inline SVG
  20. <iframe> Sandboxing
  21. Table Basics
  22. Table Semantics
  23. Spanning & Captions
  24. Form Architecture
  25. Text Inputs
  26. Selection Controls
  27. Specialized Inputs
  28. Labels & Fieldsets
  29. <datalist> Autocomplete
  30. Native Validation
  31. Form Submission
  32. <details> Accordions
  33. <dialog> Modals
  34. Popover API
  35. Invoker Commands
  36. <template> Tag
  37. data-* Attributes
  38. Web Accessibility
  39. ARIA Essentials
  40. Open Graph SEO
  41. Resource Hints

Study next

  • All coding notes
  • HTML notes home
  • HTML certification quiz
  • Online compiler
  • Interview Q&A