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>
<header>
<h1>Tabbed Video Module</h1>
<p>For a client project, they wanted a tabbed video player. The basics of it were pretty easy (and can be accomplished a number of ways) but I had a <em>very</em> hard time getting the videos to stop when I clicked on the next tab. Google eventually revealed the secret was to remove the SRC from the other IFRAMEs on click. Works for both YouTube and Vimeo embeds.</p>
<p>Hope you enjoy these videos courtesy of <a href="http://www.prettyboidrag.com" target="_blank">Pretty Boi Drag</a>!</p>
</header>
<div class="container">
<ul class="tabs">
<li>
<h2>First Video</h2>
<iframe src="https://player.vimeo.com/video/406701198" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
</li>
<li>
<h2>Second Video</h2>
<iframe src="https://player.vimeo.com/video/399275772" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
</li>
<li>
<h2>Third Video</h2>
<iframe src="https://player.vimeo.com/video/388008030" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
</li>
</ul>
</div>
</section>
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
background-color: lightgray;
line-height: 1.4;
}
header {
padding: 30px;
color: white;
width: 100%;
background-color: black;
flex: 35%;
margin-bottom: 5%;
p {
max-width: 50%;
font-size: 18px;
a {
color: yellow;
text-decoration: none;
}
}
}
section {
min-height: 100vh;
display: flex;
flex-direction: column;
.container {
width: 100%;
max-width: 80%;
margin: 0 auto;
flex: 60%;
display: flex;
justify-content: center;
align-items: center;
padding: 80px 0;
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
width: 100%;
position: relative;
padding: 0 0 56.25%;
li {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 0;
padding: 0 0 56.25%;
h2 {
background-color: black;
color: white;
position: absolute;
height: 80px;
top: -80px;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
width: calc(100% / 3);
border-left: 1px solid lightgray;
font-size: 18px;
transition: background-color 200ms ease-in;
}
&:first-child {
h2 {
border-left: none;
}
}
&.active {
z-index: 10;
h2 {
background-color: blue;
}
}
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
}
}
}
// Title/Tab
var title = $("ul.tabs li h2");
// When Browser Resizes (or Loads) Recalculate Everything
$(window).on("resize load", function () {
// Width of the UL
var ulWidth = $("ul.tabs").outerWidth();
// How many LIs are in the UL
var liCount = $("ul.tabs li").length;
// UL width devided by how many LIs equals the width of each LI
var liWidth = ulWidth / liCount;
//For each H2 add margin-left x its index. This will stagger them appropriately.
title.each(function (i) {
$(this).css({
marginLeft: liWidth * i
});
});
});
// Add the class active to just the first LI
$("ul.tabs li").first().addClass("active");
// Find the SRC of each video and add it as data-url on each LI. This becomes important since we will have to remove the SRC on each IFRAME. A simple show/hide will not stop the video from playing when you click the next tab. You have to remove the URL all together. Unfortunately, this also means each video will start completely over when you click on the tab.
$("ul.tabs li").each(function (i, video) {
var video_url = $(this).find("iframe").attr("src");
$(this).attr("data-url", video_url);
});
// Remove the SRC from each IFRAME contained in each LI. See above for explanation.
$("ul.tabs li").not(":first-child").find("iframe").attr("src", "");
// Clicking on a title first removes the class active from all other LIs, then adds it to the one you just clicked on. Next, the SRC is removed for all of the other videos and last, the URL from data-url is then added to the SRC for the video in the current LI. (Did that make sense?)
title.on("click", function () {
var video_url = $(this).parent().attr("data-url");
$("ul.tabs li").removeClass("active");
$(this).parent().addClass("active");
$("ul.tabs li").find("iframe").attr("src", "");
$(this).parent().find("iframe").attr("src", video_url);
});
Also see: Tab Triggers