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.
<p>Start spreadin' the news, I'm leavin' today</p>
<p>I want to be a part of it</p>
<p>New York, New York</p>
<p>These vagabond shoes, are longing to stray</p>
<p>Right through the very heart of it</p>
<p>New York, New York</p>
<p>I wanna to wake up, in a city that doesn't sleep</p>
<p>And find I'm king of the hill</p>
<p>Top of the heap</p>
<p>These little town blues</p>
<p>Are melting away</p>
<p>I'll make a brand new start of it</p>
<p>In old New York</p>
<p>If I can make it there, I'll make it anywhere</p>
<p>It's up to you, New York, New York</p>
<p>New York, New York</p>
<p>I want to wake up in a city that never sleeps</p>
<p>And find I'm a number one, top of the list</p>
<p>King of the hill, a number one</p>
<p>These little town blues, are melting away</p>
<p>I'm gonna make a brand new start of it</p>
<p>In old New York</p>
<p>And</p>
<p>If I can make it there</p>
<p>I'm gonna make it anywhere</p>
<p>It's up to you, New York</p>
<p>New York</p>
<p>New York</p>
p {
margin-left: 20px;
}
var PROMO_CONFIG = {
"eligible": true,
"data": {
"time_remaining_in_seconds": 1849831,
"location_dependent_data": {
"coupon_code": "SEPT_2019",
"discount_percentage": 50,
"annual_dollars": 149
},
"presentation_data": {
"background_color": "linear-gradient(87deg, #37bbab, #75c97e)",
"countdown_text": "Offer ends in ",
"text_color": "#ffffff",
"banner_text": "Subscribe now. Save discount_percentage% on an individual subscription on DataCamp and commit to learning data science and analytics.",
"time_background_color": "linear-gradient(263deg, #c06ac8, #8468c4)"
},
"promo_key": "sept_2019",
"landing_page": "https://promo.datacamp.com/",
"authorization": "upgrade",
"title": "Subscribe now. Save 50% on an individual subscription on DataCamp and commit to learning data science and analytics."
}
};
function promoBanner(data) {
const d = document;
const bannerCookiePrefix = "PROMOBANNER_";
let promoConfig = data.data, endDate = new Date().getTime() + promoConfig.time_remaining_in_seconds*1000;
const presentationData = promoConfig.presentation_data,
elBody = d.getElementsByTagName("body"),
elFirst = elBody[0].firstChild,
countdownMarkup =
"<time class='dc-ps-banner-time' data-countdown-wrapper><span data-countdown-days></span><span>days</span><span data-countdown-hours></span><span>hrs</span><span data-countdown-minutes></span><span>mins</span><span data-countdown-seconds></span><span>secs</span><span class='dc-ps-banner-time-icon'><svg width='12' height='12' viewBox='0 0 18 18' xmlns='http://www.w3.org/2000/svg'><path d='M5.69 17.92a1.7 1.7 0 0 1-1.197-2.896l6.09-6.115-6.09-6.115A1.7 1.7 0 0 1 6.888.4l7.3 7.3a1.7 1.7 0 0 1 0 2.394l-7.3 7.299c-.312.33-.743.52-1.197.528z' fill='#ffffff' fill-rule='nonzero' /></svg></span></time>",
closeMarkup =
"<button class='dc-ps-close' data-promo-close><svg width='18' height='18' viewBox='0 0 18 18' xmlns='http://www.w3.org/2000/svg'><path d='M6.86 9l-5.417 5.416a1.514 1.514 0 0 0 2.14 2.14L9 11.14l5.416 5.417a1.514 1.514 0 0 0 2.14-2.14L11.14 9l5.417-5.416a1.514 1.514 0 0 0-2.14-2.14L9 6.86 3.584 1.443a1.514 1.514 0 0 0-2.14 2.14L6.86 9z' fill='#ffffff' fill-rule='nonzero' /></svg></button>";
(styles =
"<style> @keyframes slideIn { to { max-height: 500px; opacity: 1; } } @keyframes slideOut { from { max-height: 500px; opacity: 1; } to { max-height: 0; opacity: 0.25; } } .dc-ps-banner-wrapper { font-family: Lato, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; overflow: hidden; position: sticky; top: 0; z-index: 80; } .dc-ps-banner { animation: 1s cubic-bezier(0.77, 0, 0.175, 1) 0.5s forwards slideIn; background: " +
presentationData.background_color +
"; border: 0; color: " +
presentationData.text_color +
" !important; display: block; max-height: 0; opacity: 0.25; overflow: hidden; transition: max-height 0.5s cubic-bezier(0.77, 0, 0.175, 1); text-decoration: none; } .dc-ps-banner.dc-is-hidden { animation: 0.5s cubic-bezier(0.77, 0, 0.175, 1) slideOut; } .dc-ps-banner-content { flex-grow: 1; margin: 12px 42px 12px 12px; text-align: center; } .dc-ps-banner-heading { color: " +
presentationData.text_color +
" !important; font-size: 18px; margin: 0 0 8px; } .dc-ps-banner-countdown { margin: 4px 0 0 0; } .dc-ps-banner-time { align-items: center; background: " +
presentationData.time_background_color +
"; border-radius: 4px; display: inline-flex; font-weight: bold; line-height: 1; padding: 4px 6px 4px 4px; } .dc-ps-banner-time > span { padding-left: 4px; } .dc-ps-banner-time-icon { position: relative; top: 1px; } .dc-ps-close { background: none; border: 0; cursor: pointer; position: absolute; right: 8px; top: calc(50% - 10px); transition: opacity 0.3s cubic-bezier(0.77, 0, 0.175, 1); z-index: 90; } .dc-ps-close:hover { opacity: 0.8; } @media screen and (min-width: 768px) { .dc-ps-banner-heading { font-size: 22px; margin: 0; } }</style>"),
(bannerMarkup =
"<a class='dc-ps-banner' data-ps-banner href=" +
promoConfig.landing_page +
"><div class='dc-ps-banner-content'><h5 class='dc-ps-banner-heading'>" +
promoConfig.title +
"</h5><p class='dc-ps-banner-countdown'>" +
presentationData.countdown_text +
countdownMarkup +
"</p></div></a>" +
closeMarkup +
styles);
function countdown(endDate) {
const elCountdownWrapper = d.querySelector("[data-countdown-wrapper]"),
elCountdownDays = d.querySelector("[data-countdown-days]"),
elCountdownHours = d.querySelector("[data-countdown-hours]"),
elCountdownMinutes = d.querySelector("[data-countdown-minutes]"),
elCountdownSeconds = d.querySelector("[data-countdown-seconds]");
let days, hours, minutes, seconds;
if (isNaN(endDate)) {
return;
}
setInterval(function() {
promoConfig.time_remaining_in_seconds--;
calculate(promoConfig.time_remaining_in_seconds);
}, 1000);
function calculate(secondsRemaining) {
let timeRemaining = parseInt(secondsRemaining);
if (timeRemaining >= 0) {
days = parseInt(timeRemaining / 86400);
timeRemaining = timeRemaining % 86400;
hours = parseInt(timeRemaining / 3600);
timeRemaining = timeRemaining % 3600;
minutes = parseInt(timeRemaining / 60);
timeRemaining = timeRemaining % 60;
seconds = parseInt(timeRemaining);
elCountdownDays.innerHTML = parseInt(days, 10);
elCountdownHours.innerHTML = ("0" + hours).slice(-2);
elCountdownMinutes.innerHTML = ("0" + minutes).slice(-2);
elCountdownSeconds.innerHTML = ("0" + seconds).slice(-2);
}
}
}
function setCookie(name, value, milliseconds) {
d.cookie = name + "=" + value + ";path=/;domain=COOKIE_DOMAIN;expires=" + new Date(milliseconds).toUTCString();
}
function removeBanner() {
const elBanner = d.querySelector("[data-ps-banner]");
elBanner.classList.add("dc-is-hidden");
setCookie(bannerCookiePrefix + promoConfig.promo_key, 1, promoConfig.time_remaining_in_seconds >= 86400 ? endDate - 86400000 : endDate + 86400000);
if(typeof window['snowplow'] !== undefined) {
window.snowplow('trackStructEvent','promo_banner','close',promoConfig.title,'',promoConfig.time_remaining_in_seconds)
}
}
function enableClose() {
const elClose = d.querySelector("[data-promo-close]");
elClose.addEventListener("click", removeBanner);
}
function insertBanner() {
const bannerElement = d.createElement("article");
bannerElement.classList.add("dc-ps-banner-wrapper");
elBody[0].insertAdjacentElement("afterbegin", bannerElement);
bannerElement.innerHTML = bannerMarkup;
enableClose();
}
function getCookie(name) {
var v = d.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
return v ? v[2] : null;
}
if (!d.querySelector(".dc-ps-banner-wrapper") && !getCookie(bannerCookiePrefix + promoConfig.promo_key)) {
insertBanner();
countdown(endDate);
if(typeof window['snowplow'] !== undefined) {
window.snowplow('trackStructEvent','promo_banner','open',promoConfig.title,'',promoConfig.time_remaining_in_seconds)
}
}
};
promoBanner(PROMO_CONFIG);
Also see: Tab Triggers