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.
<video-js id="myPlayerID"
data-video-id="5686632036001"
data-account="1752604059001"
data-player="BkgjFZhBfG"
data-embed="default"
data-application-id
controls></video-js>
<script src="https://players.brightcove.net/1752604059001/BkgjFZhBfG_default/index.min.js"></script>
<script src="https://players.brightcove.net/videojs-overlay/1/videojs-overlay.min.js"></script>
@import url("//players.brightcove.net/videojs-overlay/1/videojs-overlay.css");
/* * The body style is just for the
* background color of the codepen.
* Do not include in your code.
*/
body {
background-color: #111;
color: #fff;
}
/*
* Styles essential to the sample
* are below
*/
/* override default styles for overlay */
.videojs .vjs-overlay,
.vjs-overlay.vjs-overlay-top {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
min-height: 100%;
margin: auto;
left: 0;
top: 0;
background: none;
}
/* hide the overlay */
.hide-overlay .vjs-overlay {
display: none;
}
/* hide controls */
.hide-controls.video-js .vjs-control-bar,
.hide-controls .vjs-big-play-button {
display: none;
}
/* set player size */
.video-js {
width: 640px;
height: 360px;
}
/* for the registration form */
/* form layout */
.registration-form {
font-family: sans-serif;
font-size: 0.9em;
color: #333;
}
/* form header */
h1.registration-form {
font-size: 1.1em;
}
/* buttons */
button.registration-form {
font-size: 0.8em;
padding: 0.4em;
background-color: #234154;
color: #fff;
margin: 0.4em;
}
/* divs */
div.registration-form {
background-color: #f5f5f5;
opacity: 0.8;
padding: 0.5em;
}
/* inputs */
div.registration-form input {
width: 66%;
display: inline;
}
/* paragraphs */
p.registration-form {
font-weight: bold;
margin: 0;
}
videojs.getPlayer('myPlayerID').ready(function() {
var myPlayer = this,
// for handling the registration form
// user info
firstName,
lastName,
emailAddress,
registered = false,
// html for the registration form
overlayContent =
'<div id="regForm" class="registration-form"><h1 class="registration-form">To view the video, please register or login.</h1><p class="registration-form">First name: <input id="fname" type="text" size="30"></p><p>Last name: <input id="lname" type="text" size="30"></p><p class="registration-form">Email: <input id="email" type="text" size="35"></p><p class="registration-form"><button id="reg" class="registration-form">Register</button><button id="login" class="registration-form">Login</button><button id="noThanks" class="registration-form">No thanks</button></p></div><div id="regPass" class="registration-form" style="display:none;"><p class="registration-form">Choose a password: <input type="password" id="regPassword"></p><p class="registration-form"><button id="submitRegPassword" class="registration-form">Submit</button></p></div><div id="loginPass" class="registration-form" style="display:none;"><p class="registration-form">Enter your password: <input type="password" id="loginPassword"></p><p><button id="submitLoginPassword" class="registration-form">Submit</button></p></div><div id="noThanksMessage" style="display:none;"><p class="registration-form"><strong>Thanks for dropping by anyway!</strong></p></div>';
// +++ Configure the Overlay +++
// add the overlay content
myPlayer.overlay({
content: overlayContent,
overlays: [
{
align: "top",
content: overlayContent,
start: "play"
}
]
});
// +++ Play video to trigger form display +++
myPlayer.on("loadedmetadata", function() {
myPlayer.play();
});
// +++ Get references to form elements, used in form processing +++
// get element references
var fname = document.getElementById("fname"),
lname = document.getElementById("lname"),
email = document.getElementById("email"),
reg = document.getElementById("reg"),
login = document.getElementById("login"),
noThanks = document.getElementById("noThanks"),
noThanksMessage = document.getElementById("noThanksMessage"),
regForm = (document.getElementById(
"regForm"
).regPass = document.getElementById("regPass")),
regPassword = document.getElementById("regPassword"),
submitRegPassword = document.getElementById("submitRegPassword"),
loginPass = document.getElementById("loginPass"),
loginPassword = document.getElementById("loginPassword"),
submitLoginPassword = document.getElementById("submitLoginPassword");
// +++ Pause video on hide controls on player play +++
myPlayer.one("timeupdate", function() {
myPlayer.pause();
myPlayer.addClass("hide-controls");
});
// +++ Plays video when form filled out +++
/**
* hides the overlay, unhides the controls, and plays the video
* this function is called from the registration form in the iframe
* and that is why it is defined in the global scope
*/
playVideo = function() {
// hide the overlay, show the controls, play
myPlayer.addClass("hide-overlay");
myPlayer.removeClass("hide-controls");
myPlayer.play();
};
// initially hide the controls
myPlayer.addClass("hide-controls");
// +++ Process the form +++//
// everything below is for handling the registration form
// decline event listener
noThanks.addEventListener("click", function() {
// show the goodbye message
noThanksMessage.setAttribute("style", "display:block;");
});
// register event listener
reg.addEventListener("click", function() {
// here you would want to validate the field values
//
// show the create password form
regPass.setAttribute("style", "display:block;");
});
// login event listener
login.addEventListener("click", function() {
// here you would want to validate the field values
//
// show the create password form
loginPass.setAttribute("style", "display:block;");
});
// registration password event listener
submitRegPassword.addEventListener("click", function() {
// here you would want to validate the field values
firstName = fname.value;
lastName = lname.value;
emailAddress = email.value;
password = regPassword.value;
/* here you would submit the information to your
* backend registration system and
* handle the response
* here we are skipping that and will
* just set registered to true
*/
registered = true;
// invoke the function on the parent page to play the video
if (registered) {
playVideo();
}
});
// login password event listener
submitLoginPassword.addEventListener("click", function() {
// here you would want to validate the field values
firstName = fname.value;
lastName = lname.value;
emailAddress = email.value;
password = loginPassword.value;
// here you would submit the information to your
// backend authentication system
// if authentication succeeded,
// invoke the function on the parent page to play the video
parent.playVideo();
});
});
Also see: Tab Triggers