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.
<section>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 col-sm-offset-3 text-center">
<div id="video-carousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#video-carousel" data-slide-to="0" class="active"></li>
<li data-target="#video-carousel" data-slide-to="1"></li>
<li data-target="#video-carousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<!-- Button inside item so it slides with the carousel -->
<div class="play-button-wrapper">
<button class="btn btn-primary btn-video" type="submit"><i class="fa fa-play"></i></button>
</div>
<div class="inner-content">
<!-- id: Increment this each time - data-id: YouTube video ID -->
<div id="vid-0" data-id="e6xw-vh6Eu0" class="youtube-video"></div>
</div>
</div>
<div class="item">
<!-- Button inside item so it slides with the carousel -->
<div class="play-button-wrapper">
<button class="btn btn-primary btn-video" type="submit"><i class="fa fa-play"></i></button>
</div>
<div class="inner-content">
<!-- id: Increment this each time - data-id: YouTube video ID -->
<div id="vid-1" data-id="FNqGFF9hbnE" class="youtube-video"></div>
</div>
</div>
<div class="item">
<!-- Button inside item so it slides with the carousel -->
<div class="play-button-wrapper">
<button class="btn btn-primary btn-video" type="submit"><i class="fa fa-play"></i></button>
</div>
<div class="inner-content">
<!-- id: Increment this each time - data-id: YouTube video ID -->
<div id="vid-2" data-id="8FSHa77t2q0" class="youtube-video"></div>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#video-carousel" role="button" data-slide="prev">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#video-carousel" role="button" data-slide="next">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>
</section>
section {
margin:25px 0;
}
/*--------------------------
Carousel Styling
--------------------------*/
.carousel {
.inner-content {
min-height: 100px;
}
.carousel-indicators {
bottom:0; //Align to bottom of parent div
li {
margin:0 2px;
width: 18px;
height: 18px;
background: transparent;
border-color: lighten(#000, 15%);
border-width: 3px;
&.active {
background: lighten(#000, 15%);
}
}
}
.carousel-control {
font-size: 52px;
background:transparent;
text-shadow:none;
color: #000;
opacity:1;
//Hover, Focus and Active styles
&:hover, &:focus, &:active {
color:lighten(#000, 20%);
}
}
//Video Carousel
&#video-carousel {
padding-bottom:90px; //Extra padding for '.carousel-indicators'
.carousel-inner {
border:2px solid #f3f3f3;
background-color:#f3f3f3;//Prevents background image being shown when switching slides
//Inner content - Wrapper for the '.youtube-video' div
.inner-content {
min-height: 420px; //Change this for different viewports
//The YouTube video - This styling may cause issues
.youtube-video {
position: absolute;
left:0;
top:0;
}
}
//Play button and button wrapper
.play-button-wrapper {
cursor:pointer;
//Wrapper overlays the entire video
z-index: 9999;
position: absolute;
width: 100%;
height: 100%;
//This centers the play buton
display: flex;
align-items: center;
justify-content: center;
}
}
//Control buttons - Left/Right
.carousel-control {
color:rgba(#000, 0.6);
width: auto;
line-height: 400px;//Height of the items
&.left {
margin-left:-200px;
}
&.right {
margin-right:-200px;
}
//Hover, Focus and Active styles
&:hover, &:focus, &:active {
color:rgba(#000, 0.90);
}
}
}
}
/*--------------------------
Button Styling
--------------------------*/
.btn {
text-shadow:none;
//Hover, Focus and Active styles
&:hover, &:focus, &:active {
border-color: transparent;
}
//Play button
&.btn-video {
padding: 20px;
font-size: 40px;
line-height: 0;
border-radius: 0;
}
}
/*
* Carousel setup
*/
(function(){
// setup your carousels as you normally would using JS
// or via data attributes according to the documentation
// https://getbootstrap.com/javascript/#carousel
$('#video-carousel').carousel({ interval: false }); //Disable auto-slide
}());
/*
* Video carousel - Dynamically load in YouTube videos based on 'data-id'
*/
//Load the YouTube Iframe API
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
//This will be the object name for interacting with the videos in the rest of this code
var videoArray = new Array();
//Function: onYouTubePlayerAPIReady - Run when API is ready
function onYouTubePlayerAPIReady() {
//Look for video 'data-id' in the '.youtube-video' div
var videos = document.querySelectorAll('#video-carousel .youtube-video');
//Loop through each div found
for (var i = 0; i < videos.length; i++) {
//Create an array to hold the video IDs from 'data-id'
dataset = videos[i].dataset.id;
//This will be the variable name for inserting videos into the HTML divs
var divID = 'vid-' + i.toString();
//Setup video object, configure how videos should be presented
videoArray[i] = new YT.Player(divID, {
height: '100%',
width: '100%',
playerVars: {
'autoplay': 0,
'controls': 0,
'modestbranding': 1,
'rel': 0,
'showinfo': 0,
'loop': 1,
'iv_load_policy': 3
},
videoId: dataset, //Uses current looped ID from array
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
}
//Function: onPlayerReady - Run when video player is ready
function onPlayerReady(event) {
//When the Bootstrap Carousel moves
$('#video-carousel').on('slide.bs.carousel', function () {
//Find each Iframe within '#video-carousel'
$(this).find('iframe').each(function(){
//Pause all YouTube videos
event.target.pauseVideo();
});
//Show custom video button
$('.play-button-wrapper .btn-video').show();
});
}
//Function: onPlayerStateChange - Run when a videos state has changed
function onPlayerStateChange(event) {
//Find all custom video buttons within '#video-carousel'
$("#video-carousel").find('.play-button-wrapper .btn-video').each(function(){
//If video has Ended
if (event.data == YT.PlayerState.ENDED) {
$(this).fadeIn("Slow");//Fade out
$(this).find('i').attr("class", "fa fa-play");
}
//If video is Playing
if (event.data == YT.PlayerState.PLAYING) {
$(this).find('i').attr("class", "fa fa-pause");//Change icon
$(this).fadeOut("Slow");//Fade out
}
//If video is Paused
if (event.data == YT.PlayerState.PAUSED) {
$(this).fadeIn("Slow");//Fade out
$(this).find('i').attr("class", "fa fa-play");
}
//If video is Buffering
if (event.data == YT.PlayerState.BUFFERING) {
$(this).find('i').attr("class", "fa fa-circle-o-notch fa-spin fa-fw");
}
});
}
//Bind Click and Touchstart events to the custom video button
$( ".play-button-wrapper" ).bind("click touchstart", function() {
//Find the active carousel slide and target the Iframe within it
$("#video-carousel").find('.active iframe').each(function(){
//Find the integer from the div ID and split - Use objectID[1] to output the integer
var objectID = $(this).attr('id').split('-');
//If the active slide's video is Playing
if (videoArray[ objectID[1] ].getPlayerState() == 1) {
videoArray[ objectID[1] ].pauseVideo(); //Pause video on click
//If the active slide's video is Paused
} else if (videoArray[ objectID[1] ].getPlayerState() == 2) {
videoArray[ objectID[1] ].playVideo(); //Play video on click
//If the video is doing anything else
} else {
videoArray[ objectID[1] ].playVideo(); //Play video on click
}
});
});
Also see: Tab Triggers