HTML <video> class Attribute

The class attribute on a <video> tag assigns one or more classnames to the video player. Classes are used to style elements. Classnames are defined in a stylesheet or in a local <style> element.

Example

#

A class attribute styling a <video> element.

<style>
  .video {width:300px; height:240px; outline:none;
          border: 5px solid #45c9d0; padding: 10px;}
</style>

<video class="video" controls>
  <source src="/media/movie.mp4" type="video/mp4">
  <source src="/media/movie.ogg" type="video/ogg">
</video>

Using class

The class attribute assigns one or more classnames to the <video> tag.

Multiple classnames are separated by a space.

Classes (i.e. classnames) are used for styling the video element.

JavaScript uses classes to access one or more elements by classname.

Tip:  class is a global attribute that can be applied to any HTML element.


Syntax

<video class="classnames">

Values

#

Value Description
classnames One or more space-separated class names.

More Examples

A class attribute styling a <video> element.
Clicking the button toggles a classname that changes the video size.



<style>
  .video-sm { width: 320px; height: 240px; outline: none;}
  .video-lg { width: 480px; height: 360px; outline: none;}
</style>

<video id="myvideo" class="video-sm" controls>
  <source src="/media/movie.mp4" type="video/mp4">
  <source src="/media/movie.ogg" type="video/ogg">
</video>

<br/><br/>
<button onclick="toggle();">Toggle class</button>

<script>
  let toggle = () => {
     let element = document.getElementById("myvideo");
     element.classList.toggle("video-lg");
  }
</script>

Code explanation

Two CSS classes are defined in the <style> element.

The class attribute in <video> assigns one classname.

Repeatedly clicking the button toggles another class, changing the <video> control height and width.


Browser support

Here is when class support started for each browser:

Chrome
4.0 Jan 2010
Firefox
3.5 Jun 2009
IE/Edge
9.0 Sep 2012
Opera
10.5 Mar 2010
Safari
4.0 Jun 2009

You may also like

 Back to <video>
Guides