Codepen.io e-commerce tool
CodePen.io is a platform for web developers and designers to experiment, create, and share HTML, CSS, and JavaScript online.
for whom?
This is a particularly useful tool for web developers, user interface designers, and those learning to program.
for what purpose?
Code Experimentation: Users can create interactive web projects, test different coding techniques, and experiment with different effects in real time.
Project Sharing: The platform allows easy sharing of projects via links, making it easier to present work to others and collaborate within project teams.
Learning and Training: CodePen.io provides a vast database of educational projects, tutorials, and online courses to help you learn programming and develop front-end skills.
Community Building: Users can comment on and rate others' projects, share knowledge, and experience, creating an interactive community of developers.
Practice the Free Shipping Threshold Prototype
Enter your cart value and threshold, and the calculator will calculate the missing amount. With a cart value of PLN 145.50 and a threshold of PLN 199, the result is PLN 53.50.
Try the Demo · CodePen Editor Guide
How to run an example in CodePen?
Open a new Pen. Copy each snippet into the HTML, CSS, or JS field of the same name. Use the standard settings, without libraries. For a cart of 199 PLN or more, the result field should show 0 PLN.
HTML
<form id="sc-shipping-demo" aria-labelledby="sc-shipping-demo-title">
<h3 id="sc-shipping-demo-title">Kalkulator progu darmowej dostawy</h3>
<label>Wartość koszyka (PLN)<input name="cart" type="number" min="0" max="100000" step="0.01" value="145.50" required>
</label>
<label>Próg darmowej dostawy (PLN)<input name="threshold" type="number" min="0" max="100000" step="0.01" value="199" required>
</label>
<button type="submit" disabled>Sprawdź brakującą kwotę</button>
<p>Do progu brakuje <output name="remaining" aria-live="polite">—</output>
</p>
</form>CSS
#sc-shipping-demo { display:grid; gap:.65rem; margin:1rem 0; max-width:31rem; padding:1rem; border:1px solid #d9d1e1; border-radius:.5rem; }
#sc-shipping-demo h3, #sc-shipping-demo p { margin:0; }
#sc-shipping-demo label { display:grid; gap:.2rem; }
#sc-shipping-demo input { box-sizing:border-box; min-height:2.5rem; width:100%; }
#sc-shipping-demo button { justify-self:start; white-space:normal; }
#sc-shipping-demo output { font-weight:bold; }JS
(function () {
function calculateShippingDifference(cart, threshold) {
return Math.max(0, Math.round((threshold - cart) * 100) / 100);
}
(function runShippingDemo() {
const form = document.getElementById('sc-shipping-demo');
if (!form || form.dataset.ready) return;
const amount = form.elements.cart;
const limit = form.elements.threshold;
const result = form.elements.remaining;
const display = new Intl.NumberFormat(document.documentElement.lang || 'pl', {
style: 'currency',
currency: 'PLN',
});
form.dataset.ready = 'true';
for (const field of [amount, limit]) {
field.addEventListener('input', () => {
result.value = '—';
});
}
form.addEventListener('submit', (event) => {
event.preventDefault();
if (!form.checkValidity()) return;
result.value = display.format(calculateShippingDifference(amount.valueAsNumber, limit.valueAsNumber));
});
form.querySelector('button[type="submit"]').disabled = false;
})();
})();This example was created for swiatcyfrowy.pl. It uses only sample amounts and performs the calculation in the browser. Upon store implementation, the store engine calculates the threshold, taxes, discounts, and shipping costs. Use the public prototype without tokens, customer data, or real shopping carts.
CodePen.io provides an environment for creating, sharing, and learning web code, supporting the development of programming skills and creative experimentation with web technologies.