- Linking to an Audio or Video File
- Beware Browser Behavior Differs
- HTML Audio
- The HTML Element
- Example
- HTML Audio — How It Works
- HTML Autoplay
- Example
- Example
- Browser Support
- HTML Audio Formats
- HTML Audio — Media Types
- HTML Audio — Methods, Properties, and Events
- HTML Audio Tags
- How to Embed Audio and Video in HTML?
- How to embed audio in HTML?
- Syntax:
- HTML
- How to embed video in HTML?
Linking to an Audio or Video File
If you’d like to provide links to media on your site, you can do so just as easily as linking an image. Many file types exist for audio and video, the most popular these days being the MP3, QuickTime, Real, and Windows Media files.
You first place your media file into a subdirectory. As with images, this is a convention that helps you keep all your various files organized. In this case, I’ve named the subdirectory media (how’s that for brilliant?) and placed two files in it, one an MP3 audio file and the other an .avi video file. Example below shows my document and how I’ve linked to my media files.
Example: Linking to audio and video
Link to Audio Sample
Link to Video Sample
I’ve added text within the links and placed a break between the two links so they appear on top of one another rather than side by side, for the sake of clarity. This results in the links as shown in FIGURE.
Links to audio and video samples.
So far, pretty easy, right? Well, there are a few more things to do with links to give visitors an easier time managing the audio and video.
Beware Browser Behavior Differs
Different browsers and different browser configurations influence the way that linked audio and video is displayed. As the link is selected, some browsers automatically download the file into an external media player and play the audio or video clip. Other browsers provide a pop-up option asking whether you’d like to open the file with the appropriate application, or download it and save it to your hard drive. Because of these differences in behavior, it’s helpful to let your visitors know as much about the link they’re about to click on as possible.
Because most audio and video clips are quite large, it’s helpful to provide the file sizes on the page so visitors are prepared. You can do this by simply typing the details into the link or directly after it.
Some folks even go so far as to provide a range of file sizes for their low-, medium-, and high-bandwidth visitors.
Another way to assist is to place a description of the file into the title attribute of the link.
Figure: Providing helpful details for audio and video links.
This helps provide more detail to all and also alerts those folks who can’t see or hear to understand what the link is for.
Example: Adding details for your visitors
Link to Audio Sample. Size: 1,300KB
Link to Video Sample< /a>. Size: 29,000KB
HTML Audio
The HTML element is used to play an audio file on a web page.
The HTML Element
To play an audio file in HTML, use the element:
Example
HTML Audio — How It Works
The controls attribute adds audio controls, like play, pause, and volume.
The element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.
The text between the tags will only be displayed in browsers that do not support the
HTML Autoplay
To start an audio file automatically, use the autoplay attribute:
Example
Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.
Add muted after autoplay to let your audio file start playing automatically (but muted):
Example
Browser Support
The numbers in the table specify the first browser version that fully supports the element.
Element | |||||
---|---|---|---|---|---|
4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
HTML Audio Formats
There are three supported audio formats: MP3, WAV, and OGG. The browser support for the different formats is:
Browser | MP3 | WAV | OGG |
---|---|---|---|
Edge/IE | YES | YES* | YES* |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
HTML Audio — Media Types
HTML Audio — Methods, Properties, and Events
The HTML DOM defines methods, properties, and events for the element.
This allows you to load, play, and pause audios, as well as set duration and volume.
There are also DOM events that can notify you when an audio begins to play, is paused, etc.
For a full DOM reference, go to our HTML Audio/Video DOM Reference.
HTML Audio Tags
Tag | Description |
---|---|
Defines sound content | |
Defines multiple media resources for media elements, such as and |
How to Embed Audio and Video in HTML?
HTML stands for HyperText Markup Language. It is used to design web pages using a markup language. It is a combination of Hypertext and Markup language. HTML uses predefined tags and elements that tell the browser how to properly display the content on the screen. So, in this article, we will learn how to embed audio and video in HTML. In order to insert multimedia files on web pages, we already know how to insert images in HTML.
How to embed audio in HTML?
To embed audio in HTML, we use the tag. Before HTML5, audio cannot be added to web pages in the Internet Explorer era. To play audio, we used web plugins like Flash. After the release of HTML5, it is possible. This tag supports Chrome, Firefox, Safari, Opera, and Edge in three audio formats – MP3, WAV, OGG. Only Safari browser doesn’t support OGG audio format.
Syntax:
Attributes of tag
In this example, we will add an audio file to a webpage. To add audio files on the webpage, we need a notepad or another text editor.
Step 1: Open your notepad by searching notepad in your application list.
Step 2: Save a new file with a valid name following with .html extension.
Step 3: Once the HTML file is saved, you can write HTML code inside this file. In this example, we have to embed an audio file so first keep ready an audio file and save it in the same directory where your HTML is saved. Then we write HTML code as shown below code snippet following by HTML code format.
HTML
Note: Before adding an audio source must be sure that the audio file is in the same directory and specified name.
How to embed video in HTML?
To embed video in HTML, we use the tag. It contains one or more video sources at a time using tag. It supports MP4, WebM, and Ogg in all modern browsers. Only Ogg video format doesn’t support in Safari browser.
Attributes of tag
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | When the page is loaded. It specifies to play video as soon as possible. |
controls | controls | It displays video control such as play, pause, and stop. |
loop | loop | It will start the video again when it is finished. |
muted | muted | When the page is loaded video will be automatically muted. |
poster | URL | It specifies an image will be shown until video play. |
preload | auto metadata none | It specifies how the author thinks the video will be loaded when the page is ready. |
src | URL | It specifies the URL of the audio file. |
width | pixels | It specifies the width of the video area. The default value of width is ‘auto’. |
height | pixels | It specifies the height of the video area. The default value of height is ‘auto’. |
In this example, we will add a video to our webpage. To add video, we will use the tag defining source using tag. Create an HTML file just like an audio file example and save the video file in the same directory. Suppose a video file name test.mp4 save in the same directory where your HTML file was saved.