HTML Video (Video)
There are many ways to play video in HTML.
HTML Video (Videos) Playback
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
videoTry it »
Problems and Solutions
Playing video in HTML is not easy!
You need to master a number of techniques to ensure that your video files can play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac, iPad, iPhone).
In this chapter, Runoob Tutorial summarizes the problems and solutions for you.
Use tag
The tag is used to embed multimedia elements in an HTML page.
The following HTML code shows a Flash video embedded in a web page:
Example
Try it »
Problem
HTML4 cannot recognize the tag. Your page will fail validation.
If the browser does not support Flash, the video will not play
iPad and iPhone cannot display Flash videos.
If you convert the video to other formats, it still cannot play in all browsers.
Use tag
The tag is used to embed multimedia elements in an HTML page.
The following HTML snippet shows a Flash video embedded in a web page:
Example
Try it »
Problem:
If the browser does not support Flash, the video will not play.
iPad and iPhone cannot display Flash videos.
If you convert the video to other formats, it still cannot play in all browsers.
Using HTML5 Element
HTML5 The tag defines a video or movie.
The element is supported in all modern browsers.
The following HTML snippet displays a video in ogg, mp4, or webm format embedded in a web page:
Example
Your browser does not support the video tag.
Try it »
Problem:
You must convert the video into many different formats.
The element is invalid in older browsers.
The Best HTML Solution
The following example uses 4 different video formats. HTML5 The element will try to play the video in one of the mp4, ogg, or webm formats. If all fail, it falls back to .
HTML 5 + +
Try it »
Problem:
You must convert the video into many different formats
Using Hyperlinks
If a web page contains a hyperlink to a media file, most browsers will use a "helper application" to play the file.
The following code snippet shows a link to an AVI file. If the user clicks the link, the browser will launch a "helper application", such as Windows Media Player, to play the AVI file:
Example
Play a video file
Try it »
Notes on Inline Video
When a video is included in a web page, it is called an inline video.
If you plan to use inline video in a web application, you need to be aware that many people find inline video annoying.
Also note that users may have turned off the inline video option in their browser.
Our best advice is to include inline videos only where users expect to see them. A positive example is when a user needs to see a video and clicks a link, which opens the page and then plays the video.
HTML Multimedia Tags
New : HTML5 new tag.
tag
Description
Defines an embedded object. Deprecated in HTML4, allowed in HTML5.
Defines an embedded object.
Defines a parameter for an object.
New
Defines sound content
New
Defines a video or movie
New
Defines multimedia resources for the media element ( and )
New
Specifies subtitle files or other text-containing files for the media element ( and)