Embedding Videos and Audio
Yaser Rahmati | یاسر رحمتی
Embedding videos and audio in HTML is straightforward and done using the <video>
and <audio>
tags. These tags allow you to include media directly in your webpage with support for various controls like play, pause, and volume adjustment.
Embedding Videos in HTML
To embed a video, you use the <video>
tag. You can specify various attributes, including controls
, autoplay
, loop
, muted
, width
, and height
.
Basic Structure for a Video
Example 1: Embedding a Local Video
Example 2: Video with Multiple Source Formats
To ensure compatibility across browsers (since not all browsers support the same video formats), you can provide multiple video sources using the <source>
tag.
Example 3: Autoplay and Loop
You can make the video autoplay when the page loads and loop it indefinitely:
autoplay
: Starts the video automatically.loop
: Replays the video in a loop.muted
: Mutes the audio by default (required for autoplay to work in most browsers).
Example 4: Embedding a YouTube Video
If you want to embed a YouTube video, use an <iframe>
tag:
Replace VIDEO_ID
with the actual ID of the YouTube video.
Embedding Audio in HTML
To embed audio, you use the <audio>
tag. Just like with videos, you can control playback options with attributes like controls
, autoplay
, loop
, and muted
.
Basic Structure for Audio
Example 1: Embedding a Local Audio File
Example 2: Audio with Multiple Source Formats
Similar to videos, providing multiple audio sources ensures compatibility with various browsers.
Example 3: Autoplay and Loop
To have the audio play automatically and loop continuously:
autoplay
: Automatically starts the audio.loop
: Plays the audio in a loop.
Full Example with Video and Audio
Keywords
HTML
, Hypertext Markup Language
, Tags
, Elements
, Attributes
, Head
, Body
, Paragraph
, Heading
, Title
, Meta
, Link
, Image
, Anchor
, Hyperlink
, List
, Table
, Form
, Input
, Button
, CSS
, Class
, ID
, Inline
, Block
, Div
, Span
, Script
, Styles
, Font
, Color
, Background
, Margin
, Padding
, Border
, Doctype
, HTML5
, Video
, Audio
, Canvas
, SVG
External Links
🌐 Personal Website 📄 Resume 🎥 Video Archive 💼 Finance Blog 🔐 Network & Security Notebook 🎬 Aparat Channel
Last updated