HTML Media helps us to add videos, audio, and more fun elements on web pages! Let's learn how to use it π‘
π₯ HTML Video
You can use the <video>
tag to show videos.
β Example:
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
π§Ύ Explanation:
-
<video>
- This is the main tag to add a video to your webpage. -
width="320"
andheight="240"
- These set the size of the video player (in pixels). -
controls
- This shows buttons like play, pause, volume, etc. -
<source src="movie.mp4" type="video/mp4">
- This tells the browser where the video file is and what type it is. -
Your browser does not support the video tag.
- Fallback message for very old browsers.
π§ HTML Audio
You can use the <audio>
tag to play sound/music.
β Example:
<audio controls>
<source src="song.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
π§Ύ Explanation:
-
<audio>
- This tag is used to add sound or music to a webpage. -
controls
- Adds play, pause, and volume options for the user. -
<source src="song.mp3" type="audio/mpeg">
- Points to the audio file and tells the browser it's MP3. - The text inside is shown only if the browser doesn't support HTML audio.
π‘ Tip: You can add more than one <source>
tag for better browser support.
π HTML Plug-ins
Used to add PDFs, games, or other files.
β Example (PDF Viewer):
<object data="file.pdf" type="application/pdf" width="600" height="400">
PDF is not supported
</object>
π§Ύ Explanation:
-
<object>
- Used to show files like PDF or Flash inside a webpage. -
data="file.pdf"
- This is the file path of the PDF. -
type="application/pdf"
- Tells the browser itβs a PDF file. -
width
andheight
- Set the viewer size. - Inner text shows if browser canβt display the file.
β
Another Way using <embed>
:
<embed src="file.pdf" width="600" height="400">
-
<embed>
- Simpler way to show files like PDFs. - No need to write the file type.
- Works well for small previews.
πΊ Add YouTube Videos
You can add a YouTube video using an <iframe>
.
β Example:
<iframe width="560" height="315"
src="https://www.youtube.com/embed/yourvideoid"
title="YouTube video" allowfullscreen></iframe>
π§Ύ Explanation:
-
<iframe>
- A tag to embed another webpage inside your webpage. -
src="https://www.youtube.com/embed/yourvideoid"
- Replaceyourvideoid
with your actual video ID.- Example: If the link is
https://www.youtube.com/watch?v=dQw4w9WgXcQ
, the video ID isdQw4w9WgXcQ
.
- Example: If the link is
-
width
andheight
- Size of the video frame. -
title
- Helps screen readers. -
allowfullscreen
- Lets the video go full-screen.
π― Summary Table
Tag | What It Does |
---|---|
<video> |
Shows a video player |
<audio> |
Plays music or sound |
<object> |
Embeds PDF or other types of files |
<iframe> |
Shows YouTube videos or other web pages |
β¨ Tip: Try these tags in your own HTML project and see the magic!
Happy Coding π©βπ»π¨βπ»
Top comments (0)