How to embed audio in HTML?
To embed audio in HTML, we use the
Syntax:
Attributes of
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | When the page is loaded. It specifies to play audio as soon as possible. |
controls | controls | It displays audio control. |
loop | loop | It will start the audio again when it is finished. |
muted | muted | When the page is loaded audio will be automatically muted. |
preload |
auto metadata none
|
It specifies how the author thinks the audio will be loaded when the page is ready. |
src | URL | It specifies the URL of the audio file. |
Example: In this case, we will add an audio file to a web page. To add audio files on the web page, we need a notepad or another text editor program. Step 1: Open your notepad by searching notepad in your application list. Step 2: Save a newfangled 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 model, we have to embed an audio file so first gear keep ready an sound recording file and save the lapp directory where your HTML is saved. then we write hypertext markup language code as shown below code snip following by HTML code format .
HTML
< html > < head > < title >Page Title < body > < h2 >Click play button to play audio < audio src = "./test.mp3" controls>
|
Output: Note: Before adding an audio generator must be sure that the audio file is in the lapp directory and specified name .
How to embed video in HTML?
To embed video in HTML, we use the Syntax
Attributes of
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 width is ‘auto’. |
Example: In this example, we will add a video to our web page. To add television, we will use the
HTML
< html > < head > < title >Page Title < body > < h2 >Click play button to play video < video src = "./test.mp4" controls>
|
or you can use the following code :
HTML
< html > < head > < title >Page Title < body > < h2 >Click play button to play video < video controls> < source src = "./test.mp4" >
|
Output:
My Personal Notes
arrow_drop_up