Professional Documents
Culture Documents
Previous
Next Chapter
Links are found in nearly all Web pages. Links allow users to click their way from page to page.
Example
<a href="http://www.w3schools.com/">Visit W3Schools</a>
which will display like this: Visit W3Schools
Clicking on this hyperlink will send the user to W3Schools' homepage.
Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Try it yourself
Example
An anchor with an id inside an HTML document:
</body>
</html>
MAiLTO link
<!DOCTYPE html>
<html>
<body>
<p>
This is an email link:
<a href="mailto:someone@example.com?Subject=Hello%20again" target="_top">
Send Mail</a>
</p>
<p>
<b>Note:</b> Spaces between words should be replaced by %20 to ensure that
the browser will display the text properly.
</p>
</body>
</html>
How to enable <video> and <audio> tags in all major browsers
To make HTML5 video and audio tags work in all major browsers, simply add the following line
of code somewhere in the <head> of your document.
<script src="http://api.html5media.info/1.1.5/html5media.min.js"></script>
You can embed video into your page using the following code.
<video src="video.mp4" width="320" height="200" controls preload></video>
For more information and troubleshooting, please visit the video wiki page.
How to embed audio
You can embed audio into your page using the following code.
For more information and troubleshooting, please visit the audio wiki page.
Why use html5media?
HTML5 video and audio tags were designed to make embedding a video as easy as embedding
an image. They were also designed to give users a faster experience by doing away with browser
plugins such as Adobe Flash.
Unfortunately, older browsers don't support HTML5 video and audio tags, and even modern
browsers don't support a consistent set of video codecs, making embedding a video rather
difficult.
The html5media project makes embedding video or audio as easy as it was meant to be. It's a
fire-and-forget solution, and doesn't require installing any files on your server. Unlike many
other HTML5 video players, it allows people to use the video controls supplied by their own web
browser. It's one of the smallest, fastest solutions available, and as browser technology improves
it will become even faster.
Video code html
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Video code 2
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Problems, Problems, and Solutions
You must add a lot of tricks to make sure your video will play in all browsers (Internet Explorer,
Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone).
In this chapter W3Schools summarizes the problems and the solutions.
The purpose of the <embed> tag is to embed multimedia elements in HTML pages.
The following HTML fragment displays a Flash video embedded in a web page:
Example
<embed src="intro.swf" height="200" width="200">
Try it yourself
Problems
If the browser does not support Flash, the video will not play
If you convert the video to another format, it will still not play in all browsers
The purpose of the <object> tag is to embed multimedia elements in HTML pages.
The following HTML fragment displays a Flash video embedded in a web page:
Example
<object data="intro.swf" height="200" width="200"></object>
Try it yourself
Problems:
If the browser does not support Flash, the video will not play
If you convert the video to another format, it will still not play in all browsers
Problems:
The example below uses 4 different video formats. The HTML 5 <video> element tries to play
the video either in MP4, OGG, or WEBM format. If this fails, the code "falls back" to try the
<object> element. If this also fails, it "falls back" to the <embed> element:
HTML 5 + <object> + <embed>
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<source src="movie.webm" type="video/webm">
<object data="movie.mp4" width="320" height="240">
<embed src="movie.swf" width="320" height="240">
</object>
</video>
Try it yourself
Problems:
The easiest way to display videos in HTML is to use YouTube (see next chapter)!
Using A Hyperlink
If a web page includes a hyperlink to a media file, most browsers will use a "helper application"
to play the file.
The following code fragment displays a link to a Flash video. If a user clicks on the link, the
browser will launch a helper application to play the file:
Example
<a href="intro.swf">Play a video file</a>
Try it yourself
Description
<embed>
<object>
<param>
<audio>Ne
Defines sound content
w
<video>New Defines a video or movie
<source>Ne Defines multiple media resources for media elements (<video> and
w
<audio>)
<track>New Defines text tracks for media elements (<video> and <audio>)
Previous
<!DOCTYPE html>
<html>
<body>
<h2>Click the Link to Play the Object</h2>
<a href="intro.swf">Play a video file</a>
</body>
</html>
AUDIO TAGS
HTML Audio
Previous
Next Chapter
Using Plug-ins
A plug-in is a small computer program that extends the standard functionality of the browser.
Plug-ins can be added to HTML pages using the <object> tag or the <embed> tag.
These tags define containers for resources (normally non-HTML resources), which, depending
on the type, will either be displayed by the browsers, or by an external plug-in.
If a browser does not support the file format, the audio will not play without a
plug-in
If the plug-in is not installed on the users' computer, the audio will not play
If you convert the file to another format, it will still not play in all browsers
The <object tag> tag can also define a container for external (non-HTML) content.
The following code fragment should play an MP3 file embedded in a web page:
Example
<object height="50" width="100" data="horse.mp3"></object>
Try it yourself
Problems:
If a browser does not support the file format, the audio will not play without a
plug-in
If the plug-in is not installed on the users' computer, the audio will not play
If you convert the file to another format, it will still not play in all browsers
The HTML5 <audio> tag defines sound, such as music or other audio streams.
The <audio> element works in all modern browsers.
The following example uses the <audio> tag, and specifies one MP3 file (for Internet Explorer,
Chrome, and Safari), and one OGG file (for Firefox and Opera). If anything fails it displays a
text:
Example
<audio controls>
<source src="horse.mp3" type="audio/mpeg">
<source src="horse.ogg" type="audio/ogg">
Your browser does not support this audio format.
</audio>
Try it yourself
Problems:
The example below uses the HTML5 <audio> element and tries to play the audio either as MP3
or OGG. If it fails, the code "falls back" to try the <embed> element:
Example
<audio controls height="100" width="100">
<source src="horse.mp3" type="audio/mpeg">
<source src="horse.ogg" type="audio/ogg">
<embed height="50" width="100" src="horse.mp3">
</audio>
Try it yourself
Problems:
The FREE Yahoo Media Player is definitely a favorite: You simply let Yahoo do the job of
playing your songs.
It plays MP3 and a lot of other formats. You can add it to your page (or blog) with a single line of
code, and easily turn your HTML page into a professional playlist:
Example
<a href="horse.mp3">Play Sound</a>
<script src="http://mediaplayer.yahoo.com/latest"></script>
Try it yourself
To use it, insert the following JavaScript at the bottom of your web page:
<script src="http://mediaplayer.yahoo.com/latest"></script>
Then, simply link to your audio files in your HTML, and the JavaScript code automatically
creates a play button for each song:
<a href="song1.mp3">Play Song 1</a>
<a href="song2.wav">Play Song 2</a>
...
...
The Yahoo Media Player presents your readers with a small play button instead of a full player.
However, when you click the button, a full player pops up. Note that the player is always docked
and ready at the bottom of the window. Just click on it to slide it out.
Using A Hyperlink
If a web page includes a hyperlink to a media file, most browsers will use a "helper application"
to play the file.
The following code fragment displays a link to an MP3 file. If a user clicks on the link, the
browser will launch a helper application to play the file:
Example
<a href="horse.mp3">Play the sound</a>
Try it yourself
When sound is included in a web page, or as part of a web page, it is called inline sound.
If you plan to use inline sounds, be aware that many people will find it annoying. Also note that
some users might have turned off the inline sound option in their browser.
Our best advice is to include inline sounds only in pages where the user expects to hear sounds.
An example of this is a page which opens after the user has clicked on a link to hear a recording.
Description
<embed>
<object>
<param>
<audio>Ne
Defines sound content
w
<video>New Defines a video or movie
<source>Ne Defines multiple media resources for media elements (<video> and
w
<audio>)
<track>New Defines text tracks for media elements (<video> and <audio>)
Previous
Next Chapter
<!DOCTYPE html>
<html>
<body>
<embed height="50" width="100" src="horse.mp3">
<p>If you cannot hear the sound, your computer or browser doesn't support the
sound format.</p>
<p>Or, you have your speakers turned off.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<audio controls>
<source src="horse.mp3" type="audio/mpeg">
<source src="horse.ogg" type="audio/ogg">
Your browser does not support this audio format.
</audio>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<audio controls>
<source src="horse.mp3" type="audio/mpeg">
<source src="horse.ogg" type="audio/ogg">
<embed height="50" width="100" src="horse.mp3">
</audio>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p><a href="horse.mp3">Play mp3</a></p>
<p><a href="liar.wav">Play wav</a></p>
<script src="http://mediaplayer.yahoo.com/latest"></script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Linking To a Song</h2>
<p><a href="horse.mp3">Click here to play the sound</a></p>
</body>
</html>