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.
svg.svg-icon__sprite(xmlns='http://www.w3.org/2000/svg')
symbol#i-maximize(viewbox='0 0 32 32')
polyline(points="1.9,15.6 3.3,2.9 16,1.5 ")
line(x1="3.3" y1="2.9" x2="29.4" y2="29.1")
polyline(points="30.8,16.4 29.4,29.1 16.7,30.5 ")
symbol#i-search(viewbox='0 0 32 32')
circle(cx='14', cy='14', r='12')
path(d='M23 23 L30 30')
symbol#i-close(viewbox='0 0 32 32')
path(d='M2 30 L30 2 M30 30 L2 2')
symbol#i-plus(viewbox='0 0 32 32')
path(d='M16 2 L16 30 M2 16 L30 16')
symbol#i-minus(viewbox='0 0 32 32')
path(d='M2 16 L30 16')
symbol#i-play(viewbox='0 0 32 32')
path(d='M10 2 L10 30 24 16 Z')
symbol#i-pause(viewbox='0 0 32 32')
path(d='M23 2 L23 30 M9 2 L9 30')
symbol#i-backwards(viewbox='0 0 32 32')
path(d='M16 2 L2 16 16 30 16 16 30 30 30 2 16 16 Z')
symbol#i-forwards(viewbox='0 0 32 32')
path(d='M16 2 L30 16 16 30 16 16 2 30 2 2 16 16 Z')
symbol#i-star(viewbox='0 0 32 32')
path(d='M16 2 L20 12 30 12 22 19 25 30 16 23 7 30 10 19 2 12 12 12 Z')
symbol#i-checkmark(viewbox='0 0 32 32')
path(d='M2 20 L12 28 30 4')
symbol#i-chevron-top(viewbox='0 0 32 32')
path(d='M30 20 L16 8 2 20')
symbol#i-chevron-right(viewbox='0 0 32 32')
path(d='M12 30 L24 16 12 2')
symbol#i-chevron-bottom(viewbox='0 0 32 32')
path(d='M30 12 L16 24 2 12')
symbol#i-chevron-left(viewbox='0 0 32 32')
path(d='M20 30 L8 16 20 2')
symbol#i-arrow-top(viewbox='0 0 32 32')
path(d='M6 10 L16 2 26 10 M16 2 L16 30')
symbol#i-arrow-right(viewbox='0 0 32 32')
path(d='M22 6 L30 16 22 26 M30 16 L2 16')
symbol#i-arrow-bottom(viewbox='0 0 32 32')
path(d='M6 22 L16 30 26 22 M16 30 L16 2')
symbol#i-arrow-left(viewbox='0 0 32 32')
path(d='M10 6 L2 16 10 26 M2 16 L30 16')
symbol#i-caret-top(viewbox='0 0 32 32')
path(d='M30 22 L16 6 2 22 Z')
symbol#i-caret-right(viewbox='0 0 32 32')
path(d='M10 30 L26 16 10 2 Z')
symbol#i-caret-bottom(viewbox='0 0 32 32')
path(d='M30 10 L16 26 2 10 Z')
symbol#i-caret-left(viewbox='0 0 32 32')
path(d='M22 30 L6 16 22 2 Z')
symbol#i-start(viewbox='0 0 32 32')
path(d='M8 2 L8 16 22 2 22 30 8 16 8 30')
symbol#i-end(viewbox='0 0 32 32')
path(d='M24 2 L24 16 10 2 10 30 24 16 24 30')
symbol#i-eject(viewbox='0 0 32 32')
path(d='M30 18 L16 5 2 18Z M2 25 L30 25')
symbol#i-mute(viewbox='0 0 32 32')
path(d='M20 16 C20 8 15 2 15 2 L8 10 2 10 2 22 8 22 15 30 C15 30 20 24 20 16 Z')
symbol#i-volume(viewbox='0 0 32 32')
path(d='M20 16 C20 8 15 2 15 2 L8 10 2 10 2 22 8 22 15 30 C15 30 20 24 20 16 Z M21 2 C21 2 25 6 25 16 25 26 21 30 21 30 M27 4 C27 4 30 8 30 16 30 24 27 28 27 28')
symbol#i-ban(viewbox='0 0 32 32')
circle(cx='16', cy='16', r='14')
path(d='M6 6 L26 26')
symbol#i-options(viewbox='0 0 32 32')
path(d='M28 6 L4 6 M28 16 L4 16 M28 26 L4 26 M24 3 L24 9 M8 13 L8 19 M20 23 L20 29')
symbol#i-settings(viewbox='0 0 32 32')
path(d='M13 2 L13 6 11 7 8 4 4 8 7 11 6 13 2 13 2 19 6 19 7 21 4 24 8 28 11 25 13 26 13 30 19 30 19 26 21 25 24 28 28 24 25 21 26 19 30 19 30 13 26 13 25 11 28 8 24 4 21 7 19 6 19 2 Z')
circle(cx='16', cy='16', r='4')
symbol#i-heart(viewbox='0 0 32 32')
path(d='M4 16 C1 12 2 6 7 4 12 2 15 6 16 8 17 6 21 2 26 4 31 6 31 12 28 16 25 20 16 28 16 28 16 28 7 20 4 16 Z')
symbol#i-clock(viewbox='0 0 32 32')
circle(cx='16', cy='16', r='14')
path(d='M16 8 L16 16 20 20')
symbol#i-menu(viewbox='0 0 32 32')
path(d='M4 8 L28 8 M4 16 L28 16 M4 24 L28 24')
main.flexy__item.flexy--items-center.flexy--justify-center.flexy--column
section.section.flexy__item.flexy--column.flexy--items-center.space--big
header.header.accessible-hide
h2 HTML5 Video Player
article.section__article.flexy__item.flexy--column.flexy--items-center
header.header.accessible-hide
h3 A skinnable video player.
.video.flexy__item
video#video__player.video__player(autoplay preload='metadata')
//- source(src='res/video/ban-this.mp4')
source(src='http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_2160p_60fps_normal.mp4' type='video/mp4')
.video__control.flexy__item
#video__duration.video__duration.flexy__item.flexy--items-center.tooltip(data-tooltip-content='Duration')
| 00:00:00
ul.flexy__item
li#video__start.video__control__button.tooltip(data-tooltip-content='Start')
svg.svg-icon.stroke--white(fill='none')
use.use(xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#i-start')
li#video__play.video__control__button.tooltip(data-tooltip-content='Play')
svg.svg-icon.stroke--white(fill='none')
use.use(xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#i-play')
li#video__pause.video__control__button.tooltip(data-tooltip-content='Pause')
svg.svg-icon.stroke--white(fill='none')
use.use(xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#i-pause')
li#video__end.video__control__button.tooltip(data-tooltip-content='End')
svg.svg-icon.stroke--white(fill='none')
use.use(xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#i-end')
.video__control__button.video__track.flexy__child.flexy__item.flexy--items-center.tooltip(data-tooltip-content='Track')
input#video__track.video__track__range.flexy__child(type='range' step='1' min='0' max='0' value='0')
.video__control__button.volume.flexy__item.tooltip(data-tooltip-content='Volume')
svg#video__sound.svg-icon.stroke--white(fill='none')
use.use(xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#i-volume')
.video__track__range__sound
input#sound__track.video__track__range(type='range' step='1' min='0' max='10' value='10')
#video__fullScreen.video__control__button.tooltip(data-tooltip-content='Maximize')
svg.svg-icon.stroke--white(fill='none')
use.use(xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#i-maximize')
header.header
h1
a(href='http://tadaima.studio' title='Go to Tadaima')
svg.logo-tadaima.fill--white(xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 80 80')
title Tadaima Studio.
desc A group of digital interface crafters.
g
rect.st5(y='0', width='80', height='80')
lineargradient#SVGID_1_(gradientunits='userSpaceOnUse', x1='27.7468', y1='18.248', x2='52.244', y2='42.7452')
stop(offset='0', style='stop-color:#FF5572')
stop(offset='1', style='stop-color:#FF7555')
polyline.logo-tadaima--animated(style='fill:none;stroke:url(#SVGID_1_);stroke-width:2;stroke-miterlimit:10;', points='52,27 25,27 25,23 55,23 55,31 40,31 40,54 ')
lineargradient#SVGID_2_(gradientunits='userSpaceOnUse', x1='23.9948', y1='30.0043', x2='48.4901', y2='54.4996')
stop(offset='0', style='stop-color:#FF5572')
stop(offset='1', style='stop-color:#FF7555')
polyline.logo-tadaima--animated(style='fill:none;stroke:url(#SVGID_2_);stroke-width:2;stroke-miterlimit:10;', points='24,31 36,31 36,57 44,57 44,34 ')
svg.svg-bg(xmlns='http://www.w3.org/2000/svg')
defs
circle#a(cx='1468', cy='133', r='35')
mask#h(x='0', y='0', width='70', height='70', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#a')
circle#b(cx='236.5', cy='732.5', r='23.5')
mask#i(x='0', y='0', width='47', height='47', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#b')
circle#c(cx='1120.5', cy='945.5', r='28.5')
mask#j(x='0', y='0', width='57', height='57', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#c')
path#d(d='M1193.375 302.875l44.6 77.25h-89.2z')
mask#k(x='0', y='0', width='89.201', height='77.25', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#d')
path#e(d='M1610.8 513.3l34.14 59.128h-68.278z')
mask#l(x='0', y='0', width='68.277', height='59.13', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#e')
path#f(d='M51.045 967.864l38.314 66.362H12.73z')
mask#m(x='0', y='0', width='76.629', height='66.362', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#f')
path#g(d='M46.045 311.097l26.5 45.897H19.546z')
mask#n(x='0', y='0', width='52.997', height='45.897', fill='#fff')
use(xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#g')
g(style='mix-blend-mode:overlay', fill='none', fill-rule='evenodd', opacity='.35', stroke='#FFF')
use.svg-bg_element(mask='url(#h)', stroke-width='6', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#a')
use.svg-bg_element(mask='url(#i)', stroke-width='6', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#b')
use.svg-bg_element.opacity-anim(mask='url(#j)', stroke-width='6', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#c')
path.stroke-anim(d='M657.5 848.5l46 46', stroke-width='3', stroke-linecap='square')
path(d='M1360.5 1206.5l89-89M761.5 42.5l42-42', stroke-width='3', stroke-linecap='square')
use.svg-bg_element(mask='url(#k)', stroke-width='6', transform='rotate(90 1193.375 341.5)', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#d')
use.svg-bg_element(mask='url(#l)', stroke-width='6', transform='rotate(45 1610.8 542.863)', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#e')
use.svg-bg_element.rotate-anim(mask='url(#m)', stroke-width='6', transform='rotate(45 51.045 1001.045)', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#f')
use.svg-bg_element(mask='url(#n)', stroke-width='6', transform='rotate(20 46.045 334.045)', xmlns:xlink='http://www.w3.org/1999/xlink', xlink:href='#g')
.svg-icon {
stroke-width: 3;
}
.video {
width: 30em;
position: relative;
overflow: hidden;
font-size: 1.2em;
box-shadow: 0 2.5em 2.5em -1.875em rgba(0, 0, 0, .5),
0 1.25em 5em 1em rgba(0, 0, 0, .2);
&__player {
width: 100%;
height: 100%;
display: inline-block;
}
&__control {
width: 100%;
bottom: 0;
left: 0;
z-index: 2;
position: absolute;
box-sizing: border-box;
padding: 0 1em;
background-color: rgba($black, .65);
@media (min-width: 65.000em) {
opacity: 0;
transform: translate(0, 100%);
}
transition: all $fastDuration ease-in-out;
&__button {
padding: 1em .5em;
display: flex;
cursor: pointer;
position: relative;
transition: all $fastDuration ease-in-out;
&:before {
content: '';
display: inline-block;
width: 100%;
height: 1.9em;
z-index: -1;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) scale(0);
border-radius: 1.9em;
background-color: $red;
transition: all $ultraFastDuration $bezier;
}
&.volume {
flex-basis: 2em;
}
&:hover,
&.active {
&:before {
transform: translate(-50%, -50%) scale(1);
}
> .video__track__range__sound {
padding-left: .5em;
pointer-events: all;
opacity: 1;
flex: 1;
}
}
}
> .video__control__button.volume {
@media (-webkit-min-device-pixel-ratio: 2) {
display: none;
}
&:hover {
flex-basis: 5em;
}
}
}
&__duration {
padding-right: .5em;
font-size: .5em;
color: rgba($white, .5);
}
&__track {
&__range {
&[type=range] {
-webkit-appearance: inherit; /* WebKit */
width: 100%;
background-color: transparent;
}
&[type=range]:focus {
outline: none;
}
&[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 1.5em;
box-sizing: border-box;
cursor: pointer;
box-shadow: none;
background: transparent;
border-radius: 1.5em;
border: 2px solid $white;
}
&[type=range]::-webkit-slider-thumb {
box-shadow: none;
height: 1.5em;
width: 1.5em;
border-radius: 50%;
box-sizing: border-box;
border: 2px solid $white;
background: transparent;
cursor: pointer;
-webkit-appearance: none;
margin-top: -2px;
}
&[type=range]:focus::-webkit-slider-runnable-track {
// background: $red;
}
&[type=range]::-moz-range-track {
width: 100%;
height: 1.5em;
box-sizing: border-box;
cursor: pointer;
box-shadow: none;
background: transparent;
border-radius: 1.5em;
border: 2px solid $white;
}
&[type=range]:focus::-moz-range-track {
// background: $red;
}
&[type=range]::-moz-range-thumb {
box-shadow: none;
border: 0;
height: 1.5em;
width: 1.5em;
border-radius: 50%;
box-sizing: border-box;
border: 2px solid $white;
background: transparent;
cursor: pointer;
}
&[type=range]::-ms-track {
width: 100%;
height: 1.5em;
box-sizing: border-box;
cursor: pointer;
background: transparent;
border-color: transparent;
color: transparent;
border: 2px solid $white;
}
&[type=range]::-ms-fill-lower {
background: transparent;
border: 0;
border-radius: 1.5em;
box-shadow: none;
}
&[type=range]::-ms-fill-upper {
background: transparent;
border: 0;
border-radius: 1.5em;
box-shadow: none;
}
&[type=range]::-ms-thumb {
box-shadow: none;
border: 0;
height: 1.5em;
width: 1.5em;
border-radius: 50%;
box-sizing: border-box;
border: 2px solid $white;
background: transparent;
cursor: pointer;
}
&[type=range]:focus::-ms-fill-lower {
background: transparent;
}
&[type=range]:focus::-ms-fill-upper {
background: transparent;
}
&__sound {
display: flex;
width: 0;
opacity: 0;
padding-left: 0;
pointer-events: none;
transition: all $ultraFastDuration $bezier;
}
}
}
&:hover .video__control {
opacity: 1;
transform: translate(0, 0);
}
}
.tooltip {
position: relative;
&:after {
content: attr(data-tooltip-content);
position: absolute;
bottom: 100%;
left: 50%;
transform: translate(-50%, 0);
padding: 1em;
font-size: 12px;
color: $white;
background-color: $red;
opacity: 0;
transition: all $fastDuration $bezier;
}
&:hover:after {
opacity: 1;
}
}
var videoPlayer = document.getElementById('video__player'),
videoFullScreen = document.getElementById('video__fullScreen'),
videoPlay = document.getElementById('video__play'),
videoPause = document.getElementById('video__pause'),
videoEnd = document.getElementById('video__end'),
videoStart = document.getElementById('video__start'),
videoTime = document.getElementById('video__duration'),
videoTrack = document.getElementById('video__track'),
videoSound = document.getElementById('video__sound'),
soundTrack = document.getElementById('sound__track'),
videoSoundIcon = videoSound.querySelectorAll('use')[0],
videoDuration = 0,
actualMoment = 0,
updateVolume;
videoPlayer.addEventListener('loadedmetadata', function() {
videoDuration = Math.round(videoPlayer.duration);
videoTrack.setAttribute('max', videoDuration);
});
videoSound.addEventListener('click', function() {
if (soundTrack.value == 0) {
controlVolumeStatus(1);
soundTrack.value = 10;
} else {
controlVolumeStatus(0);
soundTrack.value = 0;
}
});
videoPlay.addEventListener('click', function() {
videoPlayer.play();
});
videoPause.addEventListener('click', function() {
videoPlayer.pause();
});
videoStart.addEventListener('click', function() {
videoPlayer.pause();
videoPlayer.currentTime = 0;
videoTrack.value = 0;
});
videoEnd.addEventListener('click', function() {
videoPlayer.pause();
videoPlayer.currentTime = videoDuration - 1;
videoTrack.value = videoDuration - 1;
});
videoFullScreen.addEventListener('click', function() {
if (videoPlayer.requestFullscreen) {
videoPlayer.requestFullscreen();
} else if (videoPlayer.mozRequestFullScreen) {
videoPlayer.mozRequestFullScreen(); // Firefox
} else if (videoPlayer.webkitRequestFullscreen) {
videoPlayer.webkitRequestFullscreen(); // Chrome and Safari
}
});
videoTrack.addEventListener('change', function() {
videoPlayer.currentTime = this.value;
});
updateVolume = function() {
window.requestAnimationFrame(function() {
controlVolumeStatus(soundTrack.value / 10);
});
};
soundTrack.addEventListener("mousedown", function() {
updateVolume();
soundTrack.addEventListener("mousemove", updateVolume);
});
soundTrack.addEventListener("mouseup", function() {
soundTrack.removeEventListener("mousemove", updateVolume);
});
videoPlayer.addEventListener('timeupdate', function() {
videoTrack.value = videoPlayer.currentTime;
videoTime.innerHTML = controlTimeFormat(videoPlayer.currentTime);
if (Math.round(videoPlayer.currentTime) === videoDuration) {
setTimeout(function() {
videoPlayer.currentTime = 0;
videoTrack.value = 0;
videoPlayer.pause();
}, 1000);
}
});
function controlTimeFormat(ms) {
var hr = Math.floor(ms / 3600),
min = Math.floor((ms - (hr * 3600)) / 60),
sec = Math.floor(ms - (hr * 3600) - (min * 60));
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
if (hr < 10) {
hr = "0" + hr;
}
return hr + ':' + min + ':' + sec;
}
function controlVolumeStatus(val) {
videoPlayer.volume = val;
console.log(videoPlayer.volume);
if (val === 0) {
videoSoundIcon.setAttribute('xlink:href', '#i-mute');
} else {
videoSoundIcon.setAttribute('xlink:href', '#i-volume');
}
}
setTimeout(function() {
videoPlayer.pause();
}, 500);
Also see: Tab Triggers