Full width home advertisement

How To

Tech

JavaScript

Post Page Advertisement [Top]

HTML Videos


HTML Videos


Videos can be embedded in HTML pages with several methods.

Playing Videos in HTML

Example

<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>


Problems, Problems, and Solutions

Playing videos in HTML is not easy!
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.

HTML Video - Using <embed>

The <embed> tag defines a container for external (non-HTML) content.
The following HTML fragment displays a Flash video embedded in a web page:

Example

<embed src="intro.swf" height="200" width="200">
Problems
  • If the browser does not support Flash, the video will not play
  • iPad and iPhone do not support Flash videos

HTML Video - Using <object>

The <object> tag tag can also define a container for external (non-HTML) content.
The following HTML fragment displays a Flash video embedded in a web page:

Example

<object data="intro.swf" height="200" width="200"></object>
Problems:
  • If the browser does not support Flash, the video will not play
  • iPad and iPhone do not support Flash videos

The HTML5 <video> Element

The HTML5 <video> tag defines a video or movie.
The <video> element works in all modern browsers.
The following example uses the HTML5 <video> tag, which specifies one MP4 file (for Internet Explorer, Chrome, Firefox 21+, and Safari), and one OGG file (for older Firefox and Opera). If something fails, it will display a text:

Example

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Problems:
  • You must convert your videos to many different formats
  • The <video> element does not work in older browsers

HTML Video - The Best Solution

The best solution is to use the HTML5 <video> element + the <embed> element.
The example below uses the <video> element and tries to play the video either as MP4 or OGG. If that fails, the code "falls back" to try 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">
  <object data="movie.mp4" width="320" height="240">
    <embed src="movie.swf" width="320" height="240">
  </object>
</video>
Problems:
  • You must convert your videos to many different formats

HTML Video - YouTube Solution

However, maybe the easiest way to display videos in HTML pages, is to use YouTube (see next chapter)!

HTML Video - 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>


Tips About Inline Videos

When a video is included in a web page it is called inline video.
If you plan to use inline videos, be aware that many people find it annoying. Also note that some users might have turned off the inline video option in their browser.
Our best advice is to include inline videos only in pages where the user expects to see a video. An example of this is a page which opens after the user has clicked on a link to see the video.

HTML Multimedia Tags

New : New tags in HTML5.
TagDescription
<embed>Defines an embedded object
<object>Defines an embedded object
<param>Defines a parameter for an object
<audio>NewDefines sound content
<video>NewDefines a video or movie
<source>NewDefines multiple media resources for media elements (<video> and <audio>)
<track>NewDefines text tracks for media elements (<video> and <audio>)

Bottom Ad [Post Page]