HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h1>Custom HTML5 Video Player Demo</h1>
<div id='player'>
<video id='video-element'>
<source src='https://www.w3schools.com/html/mov_bbb.mp4' type='video/mp4'>
<source src='https://www.w3schools.com/html/mov_bbb.ogg' type='video/ogg'>
</video>
<div id='controls'>
<progress id='progress-bar' min='0' max='100' value='0'>0% played</progress>
<button id='btnReplay' class='replay' title='replay' accesskey="R" onclick='replayVideo();'>Replay</button>
<button id='btnPlayPause' class='play' title='play' accesskey="P" onclick='playPauseVideo();'>Play</button>
<button id='btnStop' class='stop' title='stop' accesskey="X" onclick='stopVideo();'>Stop</button>
<input type="range" id="volume-bar" title="volume" min="0" max="1" step="0.1" value="1">
<button id='btnMute' class='mute' title='mute' onclick='muteVolume();'>Mute</button>
<button id='btnFullScreen' class='fullscreen' title='toggle full screen' accesskey="T" onclick='toggleFullScreen();'>[ ]</button>
</div>
</div>
<div style="clear:both"></div>
<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
<p>Volume bar styled using <a href="http://danielstern.ca/range.css/#/" target="_blank">range.css</a>. </p>
<hr />
<p>If you find this demo useful, please consider <a href="https://www.paypal.me/RobertGravelle/1" target="_blank">donating $1 dollar</a> (secure PayPal link) for a coffee or purchasing one of my songs from <a href="https://ax.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?term=rob%20gravelle" target="_blank">iTunes.com</a> or <a href="http://www.amazon.com/s/ref=ntt_srch_drd_B001ES9TTK?ie=UTF8&field-keywords=Rob%20Gravelle&index=digital-music&search-type=ss" target="_blank">Amazon.com</a> for only 0.99 cents each. I have also released CDs with my band <a href="https://www.cdbaby.com/Artist/IvoryKnight" target="_blank">Ivory Knight</a> and Annihilator main-man Jeff Waters.</p>
<p>Rob uses and recommends <a href="http://www.mochahost.com/2425.html" target="_blank">MochaHost</a>, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>
body {
font-family: Verdana, Geneva, sans-serif;
back body {
font-family: Verdana, Geneva, sans-serif;
background-color: lightgray;
}
p { font-size: 0.9em; }
h1 {
font-size:16px;
color:#333;
}
#player {
float:left;
padding:1em 1em .5em;
background-color:black;
border:2px solid darkgreen;
border-radius: 9px;
}
#controls {
border: 1px solid darkgreen;
width: 420px;
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 5px;
padding-bottom: 3px;
border-radius: 7px;
}
video {
border:1px solid darkgreen;
width:420px;
height:231px;
background:black;
}
button {
text-indent:-9999px;
width:16px;
height:16px;
border:none;
cursor:pointer;
background:transparent url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJEAAAAQCAYAAAAWNJ1eAAAAB3RJTUUH4AMQDS0aGLmsqwAAAAlwSFlzAAAOdAAADnQBaySz1gAAAvZJREFUeNrtmk2u0zAQxyele7gBZcOWcAJ8AKTXFVvKhnW5QbhBD4BEe4GnvgULdkaCNeUE5N2gbJGgeDJ26rhO4rFbKRX5P7mtP+YX2x1PHPdl4ErCa/W6UEmc1ACsVekGQjWyeKwrVWYN+bF63aqU99jsVJqryblvbTGyeKxrkoSPesxC/f3CosyaEBzso0DUvgL5JmZk8VhdoihXKLsnLLtLsYix1jkcf+VIU12wZUwI6LZo89xTN7J4rFOZLxxgxrjG+Vm0WNB27hlvXrWQICb6Im5IXqhU9lwi17Zuh13WS2juF/Dzq0TWW+tzLMvuj2ip47J480W8G5V+qnSwStfg+9KxDbW98V6Bw+qThGdA0WYBPQtmohu507rRYQ/ryg77RU8e9Vmlb1b+q0q3iawPqn+fEllmrF+qlDbGUDVtyRkwQs0YjFll4zpSHMsvikASyHnwVlwALbSV1aq+nU2gfRWGOJPoyaNw33VwyqYDYIXqkqwV0x5vK7sWWy6rSwUcHQgd5b1ebO+AIlvtQNh4GoSkx9RN5P0Vr/HbKTsw7P0sWT9ZxrBET5lMZNnqYs2Yvb7TNF/E4bGkM2/CelInZ0WtVPkPp90bZfvQOBAqzInS9MdTFutE52H5bl92mUxk2eKwhiOzB/L33nIgVJgTpT0tZE7+AcQ70XlY9ioU9TFHXJ9i7UglcOaU9j2FZRvPEidzyR33C9BONoGutYLOg7v99h2+7Mn79Bf8X3w4S9T26ayQ6boca8m0tw83l4msLu31u+hoY+r26ERrz1D7nMdo3ZNHPQWKGEa5LotnySrcThNZobocC/c4tP8oGYwS6AT87gysNm31+1I/6jdFZcZptyaUfwf+2cdOdfz08Gxk8VhNLm1Y3e1DzK0nhdU8kceotIJjFBVADmTq8omumMMxhIVoD8cdvKuRxWMdZTas4ed0l2HRzzNC9xudpQByIgmnj//34w+wQ2ANVf6fPfZ63IUZU+YxHOa/SfwPrCvVP/2nY6KBhDUMAAAAAElFTkSuQmCC') no-repeat 0 0; /* url('buttons.png') */
}
.pause { background-position:-19px 0; }
.stop { background-position:-38px 0; }
#volume-bar {
width: 50px;
vertical-align: middle;
padding:0px;
}
.mute { background-position:-95px 0; }
.unmute { background-position:-114px 0; }
.replay { background-position:-133px 0; }
.fullscreen {
text-indent: 0px;
color: #00c600;
background-color: black;
background-image: none;
padding: 0px;
font-weight: bold;
padding-bottom: 3px;
}
progress {
color: green;
font-size: 12px;
width: 220px;
height: 16px;
border: none;
margin-right: 10px;
background: #434343;
border-radius: 9px;
vertical-align: middle;
}
progress::-moz-progress-bar {
color:green;
background:#434343;
}
progress[value]::-webkit-progress-bar {
background-color: #434343;
border-radius: 2px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
background-color: green;
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
margin: 6.8px 0;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 4.4px;
cursor: pointer;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
background: #205928;
border-radius: 1px;
border: 1.1px solid #18d501;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 2.6px 2.6px 3.7px #00aa00, 0px 0px 2.6px #00c300;
border: 2.5px solid #83e584;
height: 18px;
width: 9px;
border-radius: 3px;
background: #439643;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7.9px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #276c30;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 4.4px;
cursor: pointer;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
background: #205928;
border-radius: 1px;
border: 1.1px solid #18d501;
}
input[type=range]::-moz-range-thumb {
box-shadow: 2.6px 2.6px 3.7px #00aa00, 0px 0px 2.6px #00c300;
border: 2.5px solid #83e584;
height: 18px;
width: 9px;
border-radius: 3px;
background: #439643;
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 4.4px;
cursor: pointer;
background: transparent;
border-color: transparent;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #194620;
border: 1.1px solid #18d501;
border-radius: 2px;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
}
input[type=range]::-ms-fill-upper {
background: #205928;
border: 1.1px solid #18d501;
border-radius: 2px;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
}
input[type=range]::-ms-thumb {
box-shadow: 2.6px 2.6px 3.7px #00aa00, 0px 0px 2.6px #00c300;
border: 2.5px solid #83e584;
height: 18px;
width: 9px;
border-radius: 3px;
background: #439643;
cursor: pointer;
height: 4.4px;
}
input[type=range]:focus::-ms-fill-lower {
background: #205928;
}
input[type=range]:focus::-ms-fill-upper {
background: #276c30;
}ground-color: lightgray;
}
p { font-size: 0.9em; }
h1 {
font-size:16px;
color:#333;
}
#player {
float:left;
padding:1em 1em .5em;
background-color:black;
border:2px solid darkgreen;
border-radius: 9px;
}
#controls {
border: 1px solid darkgreen;
width: 420px;
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 5px;
padding-bottom: 3px;
border-radius: 7px;
}
video {
border:1px solid darkgreen;
width:420px;
height:231px;
background:black;
}
button {
text-indent:-9999px;
width:16px;
height:16px;
border:none;
cursor:pointer;
background:transparent url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJEAAAAQCAYAAAAWNJ1eAAAAB3RJTUUH4AMQDS0aGLmsqwAAAAlwSFlzAAAOdAAADnQBaySz1gAAAvZJREFUeNrtmk2u0zAQxyele7gBZcOWcAJ8AKTXFVvKhnW5QbhBD4BEe4GnvgULdkaCNeUE5N2gbJGgeDJ26rhO4rFbKRX5P7mtP+YX2x1PHPdl4ErCa/W6UEmc1ACsVekGQjWyeKwrVWYN+bF63aqU99jsVJqryblvbTGyeKxrkoSPesxC/f3CosyaEBzso0DUvgL5JmZk8VhdoihXKLsnLLtLsYix1jkcf+VIU12wZUwI6LZo89xTN7J4rFOZLxxgxrjG+Vm0WNB27hlvXrWQICb6Im5IXqhU9lwi17Zuh13WS2juF/Dzq0TWW+tzLMvuj2ip47J480W8G5V+qnSwStfg+9KxDbW98V6Bw+qThGdA0WYBPQtmohu507rRYQ/ryg77RU8e9Vmlb1b+q0q3iawPqn+fEllmrF+qlDbGUDVtyRkwQs0YjFll4zpSHMsvikASyHnwVlwALbSV1aq+nU2gfRWGOJPoyaNw33VwyqYDYIXqkqwV0x5vK7sWWy6rSwUcHQgd5b1ebO+AIlvtQNh4GoSkx9RN5P0Vr/HbKTsw7P0sWT9ZxrBET5lMZNnqYs2Yvb7TNF/E4bGkM2/CelInZ0WtVPkPp90bZfvQOBAqzInS9MdTFutE52H5bl92mUxk2eKwhiOzB/L33nIgVJgTpT0tZE7+AcQ70XlY9ioU9TFHXJ9i7UglcOaU9j2FZRvPEidzyR33C9BONoGutYLOg7v99h2+7Mn79Bf8X3w4S9T26ayQ6boca8m0tw83l4msLu31u+hoY+r26ERrz1D7nMdo3ZNHPQWKGEa5LotnySrcThNZobocC/c4tP8oGYwS6AT87gysNm31+1I/6jdFZcZptyaUfwf+2cdOdfz08Gxk8VhNLm1Y3e1DzK0nhdU8kceotIJjFBVADmTq8omumMMxhIVoD8cdvKuRxWMdZTas4ed0l2HRzzNC9xudpQByIgmnj//34w+wQ2ANVf6fPfZ63IUZU+YxHOa/SfwPrCvVP/2nY6KBhDUMAAAAAElFTkSuQmCC') no-repeat 0 0; /* url('buttons.png') */
}
.pause { background-position:-19px 0; }
.stop { background-position:-38px 0; }
#volume-bar {
width: 50px;
vertical-align: middle;
padding:0px;
}
.mute { background-position:-95px 0; }
.unmute { background-position:-114px 0; }
.replay { background-position:-133px 0; }
.fullscreen {
text-indent: 0px;
color: #00c600;
background-color: black;
background-image: none;
padding: 0px;
font-weight: bold;
padding-bottom: 3px;
}
progress {
color: green;
font-size: 12px;
width: 220px;
height: 16px;
border: none;
margin-right: 10px;
background: #434343;
border-radius: 9px;
vertical-align: middle;
}
progress::-moz-progress-bar {
color:green;
background:#434343;
}
progress[value]::-webkit-progress-bar {
background-color: #434343;
border-radius: 2px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
progress[value]::-webkit-progress-value {
background-color: green;
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
margin: 6.8px 0;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 4.4px;
cursor: pointer;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
background: #205928;
border-radius: 1px;
border: 1.1px solid #18d501;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 2.6px 2.6px 3.7px #00aa00, 0px 0px 2.6px #00c300;
border: 2.5px solid #83e584;
height: 18px;
width: 9px;
border-radius: 3px;
background: #439643;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7.9px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #276c30;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 4.4px;
cursor: pointer;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
background: #205928;
border-radius: 1px;
border: 1.1px solid #18d501;
}
input[type=range]::-moz-range-thumb {
box-shadow: 2.6px 2.6px 3.7px #00aa00, 0px 0px 2.6px #00c300;
border: 2.5px solid #83e584;
height: 18px;
width: 9px;
border-radius: 3px;
background: #439643;
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 4.4px;
cursor: pointer;
background: transparent;
border-color: transparent;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #194620;
border: 1.1px solid #18d501;
border-radius: 2px;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
}
input[type=range]::-ms-fill-upper {
background: #205928;
border: 1.1px solid #18d501;
border-radius: 2px;
box-shadow: 0.9px 0.9px 1.7px #002200, 0px 0px 0.9px #003c00;
}
input[type=range]::-ms-thumb {
box-shadow: 2.6px 2.6px 3.7px #00aa00, 0px 0px 2.6px #00c300;
border: 2.5px solid #83e584;
height: 18px;
width: 9px;
border-radius: 3px;
background: #439643;
cursor: pointer;
height: 4.4px;
}
input[type=range]:focus::-ms-fill-lower {
background: #205928;
}
input[type=range]:focus::-ms-fill-upper {
background: #276c30;
}
// Get a handle to the player
player = document.getElementById('video-element');
btnPlayPause = document.getElementById('btnPlayPause');
btnMute = document.getElementById('btnMute');
progressBar = document.getElementById('progress-bar');
volumeBar = document.getElementById('volume-bar');
// Update the video volume
volumeBar.addEventListener("change", function(evt) {
player.volume = evt.target.value;
});
document.getElementById('btnFullScreen').disabled = true;
// Add a listener for the timeupdate event so we can update the progress bar
player.addEventListener('timeupdate', updateProgressBar, false);
// Add a listener for the play and pause events so the buttons state can be updated
player.addEventListener('play', function() {
// Change the button to be a pause button
changeButtonType(btnPlayPause, 'pause');
}, false);
player.addEventListener('pause', function() {
// Change the button to be a play button
changeButtonType(btnPlayPause, 'play');
}, false);
player.addEventListener('volumechange', function(e) {
// Update the button to be mute/unmute
if (player.muted) changeButtonType(btnMute, 'unmute');
else changeButtonType(btnMute, 'mute');
}, false);
player.addEventListener('ended', function() { this.pause(); }, false);
progressBar.addEventListener("click", seek);
function seek(e) {
var percent = e.offsetX / this.offsetWidth;
player.currentTime = percent * player.duration;
e.target.value = Math.floor(percent / 100);
e.target.innerHTML = progressBar.value + '% played';
}
function playPauseVideo() {
if (player.paused || player.ended) {
// Change the button to a pause button
changeButtonType(btnPlayPause, 'pause');
player.play();
}
else {
// Change the button to a play button
changeButtonType(btnPlayPause, 'play');
player.pause();
}
}
// Stop the current media from playing, and return it to the start position
function stopVideo() {
player.pause();
if (player.currentTime) player.currentTime = 0;
}
// Toggles the media player's mute and unmute status
function muteVolume() {
if (player.muted) {
// Change the button to a mute button
changeButtonType(btnMute, 'mute');
player.muted = false;
}
else {
// Change the button to an unmute button
changeButtonType(btnMute, 'unmute');
player.muted = true;
}
}
// Replays the media currently loaded in the player
function replayVideo() {
resetPlayer();
player.play();
}
// Update the progress bar
function updateProgressBar() {
// Work out how much of the media has played via the duration and currentTime parameters
var percentage = Math.floor((100 / player.duration) * player.currentTime);
// Update the progress bar's value
progressBar.value = percentage;
// Update the progress bar's text (for browsers that don't support the progress element)
progressBar.innerHTML = percentage + '% played';
}
// Updates a button's title, innerHTML and CSS class
function changeButtonType(btn, value) {
btn.title = value;
btn.innerHTML = value;
btn.className = value;
}
function resetPlayer() {
progressBar.value = 0;
// Move the media back to the start
player.currentTime = 0;
// Set the play/pause button to 'play'
changeButtonType(btnPlayPause, 'play');
}
function exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
function toggleFullScreen() {
//var player = document.getElementById("player");
if (player.requestFullscreen)
if (document.fullScreenElement) {
document.cancelFullScreen();
} else {
player.requestFullscreen();
}
else if (player.msRequestFullscreen)
if (document.msFullscreenElement) {
document.msExitFullscreen();
} else {
player.msRequestFullscreen();
}
else if (player.mozRequestFullScreen)
if (document.mozFullScreenElement) {
document.mozCancelFullScreen();
} else {
player.mozRequestFullScreen();
}
else if (player.webkitRequestFullscreen)
if (document.webkitFullscreenElement) {
document.webkitCancelFullScreen();
} else {
player.webkitRequestFullscreen();
}
else {
alert("Fullscreen API is not supported");
}
}
Also see: Tab Triggers