header-logo

CODE WITH FAHIM

HTML Audio & Video



🎡 HTML <audio> Tag:

The tag in HTML is used to embed sound files β€” like songs, podcasts, background sound effects, or even voice messages β€” directly into your web page.

Basic syntax:

<audio controls>
<source src="music.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>


Explanation:

I. <audio> β€” main tag.
II. controls β€” shows play, pause, and volume buttons.
III. <source> β€” tells the browser where the file is.

IV. Fallback text β€” shown if browser can’t play the file.



🎧 Supported audio formats:

MP3 β†’ audio/mpeg
OGG β†’ audio/ogg
WAV β†’ audio/wav



Let's hear a scary sound using the <audio> tag:

<audio autoplay >
<source src="scary-sound.mp3"
type="audio">
</audio>


Output:




🌐Browser Support:

The <audio> tag is part of HTML5, and all modern browsers support it:

Browser Supported Since Works Smoothly

Browser Supported since
βœ… Google Chrome 4.0+
βœ… Mozilla Firefox 3.5+
βœ… Microsoft Edge 9.0+
βœ… Safari 4.0+
βœ… Opera 10.5+
βœ… Mobile Browsers iOS Safari, Chrome for Android, Samsung Internet, etc.


So yeah β€” every major browser supports <audio> these days.




πŸŽ₯ HTML <video> Tag:

The <video> tag in HTML5 is used to embed videos directly in a webpage β€” no need for Flash or third-party players (thank goodness πŸ˜…).

Basic syntax:

<video width="640" height="360" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag. </video>



Explanation:

i.<video> β†’ The container that holds the video.

ii.width & height β†’ Set the display size of the video.

iii.controls β†’ Adds built-in controls (play, pause, volume, fullscreen).

iv.<source> β†’ Specifies the file and its format.


Fallback text β†’ Appears if the browser doesn’t support video.




Now,let's implement the code to watch a video.

<video width="640" height="360" controls></video>
<source src="tajmahal.mp4 type="mp4"> Your browser doesn’t support video tag(Fallback text)
</video>



Output:




🎬 Supported Video Formats:

MP4=( Chrome,Safari,Firefox,Opera)
WebM=( Chrome,Firefox,Opera)
OGG=( Chrome,Safari,Firefox,Opera)





πŸͺ„ Common Attributes Between Audio & Video Tag:

Attribute Description Example
Controls Adds play/pause/volume bar <video controls>
autoplay Starts playing automatically (muted required) <video autoplay>
loop Repeats automatically <video loop>
muted Starts muted <video muted