The Wayback Machine - https://web.archive.org/web/20241104020232/https://www.geeksforgeeks.org/how-to-display-video-controls-in-html5/
Open In App

How to display video controls in HTML5 ?

Last Updated : 26 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The HTML <video> controls attribute is used to display video controls in HTML5. It is a Boolean attribute that adds video controls like volume, pause, and play. HTML5 commonly uses formats such as OGG, MP4, OGM, and OGV because browser support for these formats varies.

Syntax

<video controls>
  <source src="video-file.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

The controls attribute adds video controls, and the <source> element allows you to specify alternative video files.

From above Syntax controls attribute adds video controls like volume, pause, and play and <source> element allows you to specify alternative video files.

Video Controls

The video control should include:

  • Play
  • Pause
  • Volume
  • Full-screen Mode
  • Seeking
  • Captions/Subtitles(if available)
  • Track(if available)

Video Tag Attributes

The <video> tag supports the following main attributes:

  • autoplay: Starts playing the video automatically, without waiting for the entire video file to finish downloading.
  • loop: Plays the video again and again.
  • muted: Mutes the player by default.
  • preload: Specifies how the video should be loaded when the page loads.
    • auto: Loads the video as soon as the page loads.
    • metadata: Loads only the video metadata.
    • none: Does not load the video when the page loads.
  • src: Defines the URL of the video that should be played by the <video> tag.

Note: Always specify the width and height of the video to prevent the webpage from slowing down due to uncertainty about how much space the video will require.

Example 1: Using src attribute in below code.

HTML
<!DOCTYPE html>
<html>

<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>

        <h3>HTML video controls Attribute</h3>

        <video width="400" height="200" controls> 
            <source src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.mp4"
                                type="video/mp4"> 
            <source src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.ogg"
                                type="video/ogg"> 
        </video>
    </center>
</body>

</html>

Output:

Example 2: Using autoplay attribute to play video automatically.

HTML
<!DOCTYPE html>
<html>

<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>

        <h3>HTML video controls Attribute</h3>

        <video width="400" height="200" autoplay controls> 
            <source src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.mp4"
                                type="video/mp4"> 
            <source src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.ogg"
                                type="video/ogg"> 
        </video>
    </center>
</body>

</html>

Output:

Example 3: Poster attribute is used to display the image while video downloading or when user click the play button.

HTML
<!DOCTYPE html>
<html>
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>

        <h3>HTML video poster Attribute</h3>

        <video width="400" height="200" controls poster=
 "https://media.geeksforgeeks.org/wp-content/uploads/20190627130930/a218.png"> 
            <source src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.mp4"
                                                            type="video/mp4"> 
            <source src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.ogg"
                                                            type="video/ogg"> 
        </video>
    </center>
</body>

</html>

Output:

The HTML <video> tag is a powerful tool for embedding videos in your web pages. By using various attributes like controls, autoplay, loop, muted, preload, and poster, you can enhance the user experience and ensure that your videos are displayed correctly across different browsers. Always remember to specify the width and height of the video to maintain optimal webpage performance.

Supported Browsers: The browsers supported by HTML video tag are listed below:

  • Google Chrome 4.0
  • Firefox 4.0
  • Apple Safari 4.0
  • Opera 10.5


Previous Article
Next Article

Similar Reads

How to add controls to an audio in HTML5 ?
In this article, we will learn how to add controls to audio in HTML5. The HTML <audio> controls attribute is used to specify the control to play audio which means it allows embedding an HTML5 music player with audio controls straight into the webpage. The current HTML5 most commonly used ogg, mp3, and wav as audio formats in the audio tag bec
2 min read
How to Hide Audio Controls in HTML5 ?
In HTML5, the <audio> element embeds audio content into web pages. By default, it comes with built-in controls like play, pause, and volume adjustment. However, there might be scenarios where you want to hide these controls for a cleaner or more customized user experience. This article explores various approaches to achieve this in HTML5. Tab
3 min read
How to make HTML5 Video Poster be same Size as Video Itself ?
To make an HTML5 video poster the same size as the video itself to achieve this you can use the HTML5 <video> elements, you can specify a poster frame that will be displayed before the video starts playing. To ensure that the poster image is the same size as the video itself, you should use an image with the same dimensions as the video. Belo
3 min read
HTML | DOM Video controls Property
The Video controls property is used to set or return whether a video should display standard video controls or not. The <video> controls attribute are reflected by this property. The video controls included in the property are: PlayPauseVolumeFullscreen ModeSeekingCaptions/SubtitlesTrack Syntax: Returning the controls property:videoObject.con
2 min read
HTML | <video> controls Attribute
The HTML <video> controls Attribute is used to specify the control to play video. It is the Boolean value. This attribute is new in HTML5. The video control should include: PlayPauseVolumeFull-screen ModeSeekingCaptions/Subtitles(if available)Track(if available) Syntax: <video controls> Example: C/C++ Code &lt;!DOCTYPE html&gt;
1 min read
HTML5 MathML display Attribute
This attribute holds the value of rendering of HTML element. There can be two value block which means that this element will be displayed outside the current span of text, inline which means that this element will be displayed inside the current span of text. This attribute is accepted by <math> tag only. Syntax: <element display="block|in
1 min read
How to display play pause and mute buttons in HTML5 ?
To display play, pause, and mute buttons in an audio file through HTML5, we can use JavaScript methods such as "play()", "pause()" and ".muted". With this feature of audio display with only play, pause, and mute buttons, we're essentially giving the user control over the playback of the audio file according to their preference. Syntax to display Au
2 min read
What is the difference between display: inline and display: inline-block in CSS?
The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If we need to display the elements that are laid out a
4 min read
How display: inline is different from display: inline-block in CSS ?
In this article, we will know about the display property in CSS, along with understanding the 2 different property values for display property, i.e., display: inline & display: inline-block properties, & will understand their basic differences & implementation through the examples. The display property facilitates setting the element by
3 min read
What is the difference between display:inline-flex and display:flex in CSS ?
In this article, we will see the display property & its values, i.e. the inline-flex & flex, in order to specify the display behavior of an element, along with understanding their basic differences & will illustrate them through the examples. Both CSS display: inline-flex and display: flex properties are used to create flexible layouts.
3 min read
How to add video in HTML5 ?
In This article, we will define how to add video content using a <video> element in the document. Before HTML5 came into existence, videos could only be played in a browser using a plugin like flash, but after the release of HTML5, adding a video to a web page is easy as adding an image. The HTML5 “video” element specifies a standard way to e
1 min read
How to set the height and width of the video player in HTML5 ?
In this article, we will learn to set the width and height of the video player in HTML5. The following are the two scenarios The width and height of the video are fixed.Make the video respond to your screen width. Approach: The HTML5 width and height attributes of the video tag are used to set the height and width of the video player respectively.
2 min read
How to mute video using HTML5 ?
The purpose of this article is to mute video using HTML5. Approach: Video Tag is new to HTML5. Users can use muted attributes in video tags to mute a video. The muted attribute is a boolean attribute. When present, it specifies that the audio output of the video should be muted. Syntax: <video controls muted> Example: In this example, we are
1 min read
How to Hide Full Screen Button of the Video Tag in HTML5 ?
The <video> element is used to embed video content on the web page. It allows the addition of video files in many formats such as MP4, WebM, etc. This element supports attributes like controls, autoplay, and loop to control video playback. It also enables the addition of captions and subtitles for accessibility. Preview: Approach:Create a str
1 min read
How to add Label above Video in HTML5 ?
In HTML5, putting a label above a video is important for helping users understand and interact with the content better. There are two easy ways to do this: using the figure and figcaption elements, or just the label tag itself. By using these methods, you can easily add informative labels above your videos, making them more accessible and improving
2 min read
How to Generate Video from Images in HTML5 ?
Generating a video from images in HTML5 involves utilizing HTML, CSS, and JavaScript to dynamically create a video by stitching together a sequence of images. Additionally, the transition effects and frame rate control ensure a seamless and optimized viewing experience for the generated video. ApproachThe HTML file contains a basic structure with a
3 min read
How to Play Video in Reverse in HTML5 ?
To play a video in reverse in HTML5, you can use JavaScript to control the playback direction. This involves manipulating the video's current time property to decrement it, creating the effect of reverse playback. This technique allows for custom control over video playback behavior directly within the browser. PrerequisitesHTMLCSSJavaScriptApproac
2 min read
How to define the URL of the video file in HTML5?
In this article, we will learn how to define the URL of a video in HTML. The <video> tag is used to embed video files on a web page. This displays a video player along with the player controls depending on the browser. The source of the video can either be a singular one or it can be made to support multiple formats of the video so that multi
3 min read
How to preload the video when the page loads in HTML5?
The HTML <preload> attribute is used to specify the way the developer thinks the video should be loaded when the page loads. Syntax<video preload=""> </video>There are 3 values for preload attribute auto, metadata and none. Note: An empty string leads to the default auto attribute value. Example 1: The following example demonstrat
1 min read
How to Play a Small Clip from a Long Video in HTML5?
Playing a specific clip from a longer video in HTML can enhance user experience and streamline content delivery. Sometimes, you may have a long video but only want to showcase a specific portion of it on your website. In such cases, playing a small clip from a longer video can be useful. HTML5 offers several approaches to achieve this seamlessly. M
3 min read
HTML | <audio> controls Attribute
The HTML <audio> controls attribute is used to specify the control to play audio. It is the Boolean value. This attribute is new in HTML5. The audio control attribute contains the following property: PlayPauseSeekingVolume Syntax: <audio controls> Example: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt
1 min read
HTML DOM Audio controls Property
The Audio controls property is used for setting or returning whether audio should display standard audio controls or not. The <audio> controls attribute is reflected by this property. The audio controls included in the property are: PlayPauseSeekingVolume Syntax: Return the control property:audioObject.controlsSet the control property:audioOb
1 min read
How to enable/disable all input controls inside a form element using jQuery ?
Give an HTML document containing a form element. The form element contains input elements, option elements, and button elements. The task is to enable or disable all input controls inside a form using jQuery. It can be done by using prop() method. Using prop() Method: It is used to set or return the properties and values for the selected elements.
3 min read
How to remove controls of a text canvas using Fabric.js ?
In this article, we are going to see how to remove the controls of a text canvas using FabricJS. The canvas means text written is movable and can be stretched according to requirement but we will remove the controls so that it cannot be resized or rotated but only be moved. Further, the text itself cannot be edited like a textbox.Approach: To make
2 min read
How to remove only rotation controls of a canvas-type text using Fabric.js ?
In this article, we are going to see how to remove only the rotation controls of a canvas-like text using FabricJS. The canvas means text written is movable and can be stretched according to requirement but we will remove the rotation controls so that it cannot be rotated but only be moved and resized. Further, the text itself cannot be edited like
2 min read
Mouse swipe controls in Angular 9 using HammerJS
Angular is an application design framework and development platform for creating efficient and sophisticated single-page apps. It has been changed a lot from its first release. And it keeps adding new features and modifications in its releases which is a good thing. But sometimes what we have used in the previous version stops working in the latest
4 min read
How to design form controls for mobiles using jQuery Mobile Square-UI Theme plugin ?
In this article, we will learn how to design the form controls for mobile-oriented applications using the jQuery Mobile Square-UI Theme plugin. Prerequisite: Download the pre-compiled required library files from the given link and save it in your working folder for the following implementation. Example 1: C/C++ Code <!DOCTYPE html> <html
4 min read
How to design form controls for mobiles using jQuery Mobile BootstrapTheme plugin ?
The purpose of this article is to introduce some form or user input controls for mobile web designers using the jQuery Mobile Bootstrap Theme plugin. These CSS based UI controls are very attractive and interactive and help developers build beautiful apps. To design and implement the plugin, please download the required pre-compiled files or librari
5 min read
How to change the size of Form controls in Bootstrap ?
Bootstrap allows to change the size of form controls using .form-control classes. For default size .form-control is used, for smaller size we can use .form-control class along with .form-control-sm and for larger size we can use .form-control class along with .form-control-lg. Syntax : For default size:class="form-control" For small size:class="for
2 min read
Foundation CSS Forms Custom Controls
Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is
3 min read
three90RightbarBannerImg