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.
<!-- Pricing Container -->
<div class="max-w-6xl mx-auto px-4 py-8">
<!-- Billing Toggle -->
<div class="text-center mb-8">
<div class="inline-flex items-center bg-gray-100 rounded-lg p-1">
<button id="monthlyBtn" class="px-4 py-2 rounded-md text-sm bg-white" onclick="updateBillingCycle('month')">Monthly</button>
<button id="yearlyBtn" class="px-4 py-2 rounded-md text-sm" onclick="updateBillingCycle('year')">Yearly (Save 20%)</button>
</div>
</div>
<!-- Pricing Grid -->
<div class="grid md:grid-cols-3 gap-8">
<!-- Starter Plan -->
<div class="bg-white rounded-lg shadow-lg p-8">
<h3 class="text-xl font-semibold mb-4">Starter</h3>
<div class="mb-4">
<span id="starter-price" class="text-4xl font-bold">$10.00</span>
<span class="text-gray-500 ml-1">/month</span>
</div>
<button onclick="openCheckout('starter')" class="w-full bg-blue-600 text-white rounded-lg px-4 py-2 hover:bg-blue-700 transition-colors">
Get started
</button>
</div>
<!-- Pro Plan -->
<div class="bg-white rounded-lg shadow-lg p-8 border-2 border-blue-500 relative">
<div class="absolute -top-3 right-12 bg-blue-500 text-white px-3 py-1 rounded-full text-sm">Popular</div>
<h3 class="text-xl font-semibold mb-4">Pro</h3>
<div class="mb-4">
<span id="pro-price" class="text-4xl font-bold">$30.00</span>
<span class="text-gray-500 ml-1">/month</span>
</div>
<button onclick="openCheckout('pro')" class="w-full bg-blue-600 text-white rounded-lg px-4 py-2 hover:bg-blue-700 transition-colors">
Get started
</button>
</div>
<!-- Enterprise Plan -->
<div class="bg-white rounded-lg shadow-lg p-8">
<h3 class="text-xl font-semibold mb-4">Enterprise</h3>
<div class="mb-4">
<span class="text-4xl font-bold">Contact us</span>
</div>
<button onclick="window.location.href='mailto:sales@example.com'" class="w-full bg-gray-600 text-white rounded-lg px-4 py-2 hover:bg-gray-700 transition-colors">
Let's talk
</button>
</div>
</div>
<!-- Country Selector -->
<!-- Remove from live implementations -->
<div class="mt-12 p-6 bg-blue-50 border border-blue-200 rounded-lg">
<div class="md:flex md:items-center md:justify-between">
<div class="md:flex-1 md:pr-8">
<h3 class="text-lg font-semibold mb-2">Explore customer localization</h3>
<p class="mb-4 md:mb-0 text-sm text-gray-600">
Test how price localization works by changing the country. You can pass a country, IP address, or existing customer ID to <code class="bg-blue-100 px-1 py-0.5 rounded">Paddle.PricePreview()</code> to get localized prices. In live implementations, we recommend using an IP address.
</p>
</div>
<div class="text-center md:text-right md:flex-shrink-0">
<select id="countrySelect" class="px-4 py-2 rounded-lg border border-gray-300">
<option value="US">πΊπΈ United States</option>
<option value="GB">π¬π§ United Kingdom</option>
<option value="DE">π©πͺ Germany</option>
<option value="FR">π«π· France</option>
<option value="AU">π¦πΊ Australia</option>
</select>
</div>
</div>
</div>
</div>
/*
This sample uses Tailwind for styling.
See: https://tailwindcss.com/
*/
// Configuration
// Replace with values from your sandbox account
const CONFIG = {
clientToken: "test_7d279f61a3499fed520f7cd8c08",
prices: {
starter: {
month: "pri_01gsz8ntc6z7npqqp6j4ys0w1w",
year: "pri_01gsz8s48pyr4mbhvv2xfggesg"
},
pro: {
month: "pri_01gsz8x8sawmvhz1pv30nge1ke",
year: "pri_01gsz8z1q1n00f12qt82y31smh"
}
}
};
// UI elements
const monthlyBtn = document.getElementById("monthlyBtn");
const yearlyBtn = document.getElementById("yearlyBtn");
const countrySelect = document.getElementById("countrySelect");
const starterPrice = document.getElementById("starter-price");
const proPrice = document.getElementById("pro-price");
// State
let currentBillingCycle = "month";
let currentCountry = "US";
let paddleInitialized = false;
// Initialize Paddle
function initializePaddle() {
try {
Paddle.Environment.set("sandbox");
Paddle.Initialize({
token: CONFIG.clientToken,
eventCallback: function (event) {
console.log("Paddle event:", event);
}
});
paddleInitialized = true;
updatePrices();
} catch (error) {
console.error("Initialization error:", error);
}
}
// Update billing cycle
function updateBillingCycle(cycle) {
currentBillingCycle = cycle;
monthlyBtn.classList.toggle("bg-white", cycle === "month");
yearlyBtn.classList.toggle("bg-white", cycle === "year");
updatePrices();
}
// Update prices
async function updatePrices() {
if (!paddleInitialized) {
console.log("Paddle not initialized yet");
return;
}
try {
const request = {
items: [
{
quantity: 1,
priceId: CONFIG.prices.starter[currentBillingCycle]
},
{
quantity: 1,
priceId: CONFIG.prices.pro[currentBillingCycle]
}
],
address: {
countryCode: currentCountry
}
};
console.log("Fetching prices:", request);
const result = await Paddle.PricePreview(request);
result.data.details.lineItems.forEach((item) => {
const price = item.formattedTotals.subtotal;
if (item.price.id === CONFIG.prices.starter[currentBillingCycle]) {
starterPrice.textContent = price;
} else if (item.price.id === CONFIG.prices.pro[currentBillingCycle]) {
proPrice.textContent = price;
}
});
console.log("Prices updated:", result);
} catch (error) {
console.error(`Error fetching prices: ${error.message}`);
}
}
// Open checkout
function openCheckout(plan) {
if (!paddleInitialized) {
console.log("Paddle not initialized yet");
return;
}
try {
Paddle.Checkout.open({
items: [
{
priceId: CONFIG.prices[plan][currentBillingCycle],
quantity: 1
}
],
settings: {
theme: "light",
displayMode: "overlay",
variant: "one-page"
}
});
} catch (error) {
console.error(`Checkout error: ${error.message}`);
}
}
// Event Listeners
countrySelect.addEventListener("change", (e) => {
currentCountry = e.target.value;
updatePrices();
});
// Initialize on page load
document.addEventListener("DOMContentLoaded", initializePaddle);
Also see: Tab Triggers