The class attribute assigns one or more classnames to the <video> tag.
Classnames are defined in a stylesheet or in a local <style> element.
Classes, i.e. classnames, are used to style elements.
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>
Classes (i.e. classnames) are used for styling the video element.
Multiple classnames are separated by a space.
JavaScript uses classes to access elements by classname.
Tip: class is a global attribute that can be applied to any HTML element.
<video class="classnames">
Value | Description |
---|---|
classnames | One or more space-separated class names. |
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>
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.
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 |
Back to <video>