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.
<header>
<div class="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 18">
<path d="M21.587 0l-1.475 4.193H9.565c-.552 0-.976.111-1.274.332-.165.118-.343.34-.537.663-.03.045-.044.155-.044.332 0 .177-.008.265-.023.265a.637.637 0 0 0-.044.243c0 .443.335.664 1.005.664h8.112c.909 0 1.65.212 2.224.636.573.425.86 1.032.86 1.822 0 .417-.089.872-.268 1.364-.447 1.207-1.103 2.965-1.967 5.275-.238.67-.521 1.147-.849 1.43-.402.372-.968.559-1.698.559H0l1.497-4.194h10.526c.953 0 1.564-.332 1.832-.998.224-.574.365-.846.425-.816a.772.772 0 0 0 .022-.182c0-.469-.38-.703-1.14-.703H5.05c-.893 0-1.627-.214-2.2-.644-.574-.43-.861-1.044-.861-1.844 0-.415.081-.859.246-1.333 1.132-3.272 1.713-4.968 1.743-5.087C4.305.659 5.154 0 6.525 0h15.062M33.476 17.778l4.257-12.201c.045-.15.067-.305.067-.469 0-.61-.268-.915-.803-.915h-6.44c-.861 0-1.456.462-1.782 1.384l-4.234 12.2h-4.858L25.878 0H54.49c1.768 0 2.652.758 2.652 2.275 0 .64-.171 1.443-.513 2.41l-4.635 13.093h-4.791L51.46 5.577c.045-.15.067-.305.067-.469 0-.61-.268-.915-.802-.915h-6.44c-.862 0-1.457.462-1.783 1.384l-4.234 12.2h-4.792M77.897 3.546l-4.956 14.232H58.163c-.807 0-1.409-.268-1.806-.805-.322-.462-.484-1.042-.484-1.743 0-.477.074-.916.22-1.319l1.894-5.52c.456-1.341 1.388-2.012 2.798-2.012h11.32l.33-1.038c.044-.132.066-.257.066-.375 0-.515-.33-.772-.991-.772H59.42L60.872 0H75.76c1.556 0 2.334.788 2.334 2.364a3.5 3.5 0 0 1-.198 1.182m-7.246 7.027h-7.576c-.69 0-1.145.317-1.366.95l-.286.77a1.902 1.902 0 0 0-.088.544c0 .498.25.747.749.747h7.532l1.035-3.01M95.238 0l-1.495 4.193h-6.175c-.506 0-.955.116-1.35.346-.394.231-.643.502-.747.814l-4.417 12.425H76.19l5.355-15.19C82.155.862 83.485 0 85.538 0h9.7M96.722 0l-1.484 4.228h7.158l-4.692 13.55 4.757-.023v.023l4.692-13.55h6.94L115.557 0H96.722M129.833 6.452c.102-.148-.372 1.232-1.422 4.139h-8.77l-2.492 7.187h-4.768L118.548 0h13.515l-1.42 4.183h-8.792l-.788 2.27h8.77M134.342 0l-6.088 17.778h4.706L139.048 0h-4.706M141.167 0l-1.484 4.228h7.158l-4.692 13.55 4.757-.023v.023l4.692-13.55h6.94L160 0h-18.833"></path>
</svg>
<span>
Online Sizing
</span>
</div>
<nav class="links">
<a href="https://www.onlinesizing.bike" target="_blank">Online Sizing Website</a>
<a href="https://docs.onlinesizing.bike" target="_blank">Docs</a>
</nav>
</header>
<main class="content">
<section class="bike-image">
<img src="https://products.scott-sports.com/280761/2000/280761.jpg" alt="Scott Axis eRIDE 10" />
</section>
<section class="product-info">
<p class="manufacturer">Scott</p>
<h1 class="product-title">Axis eRIDE 10</h1>
<div class="product-meta">
<p class="price">1.999,- €</p>
<ul class="sizes">
<li data-size="XS">XS</li>
<li data-size="S">S</li>
<li data-size="M">M</li>
<li data-size="L">L</li>
<li data-size="XL">XL</li>
</ul>
<div class="oz-buttons">
<div class="oz-container" data-oz-widget="launcher" data-oz-code="7615523134243" data-oz-name="Scott Axis eRIDE 10" data-oz-image="https://products.scott-sports.com/280761/2000/280761.jpg" data-oz-units="imperial" data-oz-confirm-size-label="Custom Confirm Text"></div>
<div class="oz-container" data-oz-widget="launcher" data-oz-code="7615523134243" data-oz-name="Scott Axis eRIDE 10" data-oz-image="https://products.scott-sports.com/280761/2000/280761.jpg" data-oz-language="de"></div>
</div>
<nav class="buy">
<button disabled class="add-to-basket">Add to basket</button>
</nav>
</div>
</section>
</main>
<aside class="callout">
<p>This is a Demo Page for the Online Sizing v2 widget.</p>
<p>Since this is a codepen, please feel free to open the editor view and change attributes on for example the "What's my size?" button.</p>
<p>Thank you so much for testing with us – if you need anything at all please reach us at: <a href="mailto:[email protected]">onlinesizing@smartfit.bike</a></p>
</aside>
$breakpoint: 650px;
:root {
--cta: #96bc33;
--cta-darker: #749322;
--highlight: #a4cb3e3d;
--primary: #303538;
--callout: #ffbf59;
}
body {
padding: 5vw;
font-size: 20px;
color: var(--primary);
}
header {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
margin-bottom: 5vh;
a {
font-size: 0.85em;
text-decoration: none;
border: 2px solid;
border-radius: 0.3em;
padding: 0.2em 0.4em;
color: var(--cta);
}
}
.logo {
width: 180px;
svg {
fill: var(--cta);
}
span {
text-transform: uppercase;
font-size: 0.85rem;
letter-spacing: 0.05em;
}
}
.content {
display: grid;
margin-bottom: 2vh;
@media (min-width: $breakpoint) {
grid-template-columns: 2fr minmax(300px, 1fr);
gap: 5vw;
align-items: center;
}
}
.product-meta {
display: grid;
gap: 2vh;
& > * {
margin: 0;
}
}
.bike-image {
img {
width: 100%;
max-width: 800px;
display: block;
}
}
.manufacturer {
margin: 0;
}
.product-title {
font-size: 20px;
margin-top: 0.25em;
@media (min-width: $breakpoint) {
font-size: 28px;
}
}
.price {
font-style: italic;
text-decoration: underline;
text-decoration-color: hotpink;
font-size: 1.25rem;
}
.sizes {
list-style: none;
padding-left: 0;
display: flex;
li {
padding: 1em;
border: 2px solid;
line-height: 1;
font-size: 0.85em;
cursor: pointer;
border-radius: 0.5em;
&.selected {
color: var(--cta);
background-color: var(--highlight);
}
&:not(:last-child) {
margin-right: 0.2em;
}
}
}
.oz-buttons {
font-size: 0.85rem;
}
.add-to-basket {
width: 100%;
max-width: 450px;
}
button {
appearance: none;
outline: none;
border: none;
background-color: var(--cta);
color: white;
padding: 0.75em 1em;
line-height: 1;
border-radius: 0.5em;
cursor: pointer;
border: 2px solid;
transition: border-color 250ms ease;
&[disabled] {
opacity: 0.5;
pointer-events: none;
}
&:hover {
border-color: var(--cta-darker);
}
}
.callout {
border-radius: 0.5em;
font-size: 0.85rem;
background-color: lightyellow;
padding: 1em;
border: 2px solid var(--callout);
max-width: 650px;
a {
color: var(--cta);
}
p {
margin-top: 0;
margin-bottom: 0.5em;
&:last-child {
margin-bottom: 0;
}
}
}
/**
* Function to select frame size on your product page.
* You probably have this already from Online Sizing v1.
*/
const selectSizeInShop = (payload) => {
console.log(payload);
const { size } = payload;
const targetSizeElement = document.querySelector(
`.sizes li[data-size="${size}"]`
);
selectSize(targetSizeElement);
};
/**
* NEW: Global Online Sizing Config
*/
const OZ_CONFIG = {
settings: {
apiKey: "$oz_$7W0iJd8UhnY1gBTRWnMTLu4c2jadCAqhzPiVdXl9kKsFuP86D3rB2"
},
events: {
confirmSize: {
callback: selectSizeInShop
}
}
};
/**
* NEW: Embed script
* This takes the OZ_CONFIG variable you just declared to initialize all widgets on the page
*/
((win, doc, script, key, config, src) => {
win["___OnlineSizing"] = key;
win["___OnlineSizingConfig"] = config;
const js = doc.createElement(script);
js.id = key;
js.src = src;
js.async = true;
const scripts = doc.getElementsByTagName(script);
const lastScript = scripts[scripts.length - 1];
lastScript.parentNode.insertBefore(js, lastScript);
})(
window,
document,
"script",
"oz",
OZ_CONFIG,
`https://widgets.onlinesizing.bike/loader.js`
);
/**
* --------------------------------------------------------------------- *
* Unrelated JS stuff for just this Demo page
*/
const sizeButtons = document.querySelectorAll(".sizes li");
const addToBasketButton = document.querySelector(".add-to-basket");
const selectSize = (el) => {
if (el.classList.contains("selected")) {
el.classList.remove("selected");
addToBasketButton.disabled = true;
} else {
Array.from(sizeButtons).forEach((button) =>
button.classList.remove("selected")
);
el.classList.add("selected");
addToBasketButton.removeAttribute("disabled");
}
};
Array.from(sizeButtons).forEach((button) => {
button.addEventListener("click", () => {
selectSize(button);
});
});
Also see: Tab Triggers