Mobile Checkout Screen — Free HTML CSS JS Snippet

Mobile Checkout Screen · Mobile · Plain HTML, CSS & JS · Live preview

Share & Support

What's included

Features

Live order total
One recalc function keeps every figure in sync.
Quantity steppers
Plus/minus with a floor of one per item.
Working promo code
SAVE10 applies a real 10% discount.
Three promo states
Applied, invalid, and empty feedback.
Custom radios
Real inputs styled with a sibling selector.
Sticky pay bar
Total stays visible below the scroll area.
Confirmed state
Place-order button flips to green on tap.
No dependency
Pure HTML, CSS, and vanilla JavaScript.

About this UI Snippet

Mobile Checkout Screen — Order Review UI

Screenshot of the Mobile Checkout Screen snippet rendered live

A checkout screen is the last, highest-stakes step in mobile commerce — a delivery address, the cart items with quantity controls, a payment method, a promo field, and an order summary under a sticky pay button. This snippet builds a complete, calculating one inside a CSS phone frame: quantity steppers update the subtotal, a promo code applies a real discount, and the total recomputes live in both the summary and the sticky bar — in HTML, CSS, and vanilla JavaScript with no dependency.

The live order math

Each cart item carries a data-price attribute and shows a quantity. A single recalc() function walks every item, multiplies price by quantity, sums the subtotal, applies the current discount rate, adds flat shipping, and writes the result to the subtotal, discount, total, and sticky-bar figures at once. Centralizing the math in one function means every interaction — stepper or promo — calls the same code path, so the numbers can never drift out of sync.

Quantity steppers with a floor

Each item has a minus/plus stepper. The plus button always increments; the minus button only decrements while the quantity is above one, so an item never drops to zero from the stepper — the same guard real carts use to force an explicit remove action instead. Every change re-runs recalc().

A promo code that actually discounts

Entering SAVE10 and tapping Apply sets a 10% discount rate, reveals the previously hidden discount line in green, and lowers the total; an unknown code shows a red error and clears any discount. The code is upper-cased before comparison so save10 works too, and an empty field prompts you to enter one — the three states every promo field needs.

Custom payment radios

The payment methods are real radio inputs, visually hidden, with a styled .mck-pdot ring driven by the :checked ~ sibling selector so only one can be active. Because they are genuine radios grouped by name, keyboard and screen-reader selection work without any JavaScript.

Sticky action bar

The place-order button lives in a bar pinned below the scroll area, showing the total again so it stays visible as you scroll the summary. Tapping it flips the button to a green confirmed state.

Accessibility and performance

The payment options are genuine radio inputs grouped by name, so arrow keys move between them and screen readers announce the selected method — no custom keyboard handling needed. The steppers and promo controls are real buttons with aria-labels, and the promo feedback is plain text that assistive tech reads on change, with color reinforced by wording rather than carried by color alone. Performance is trivial here: the recalc() function does a single pass over a handful of items and writes a few text nodes, so it can run on every stepper tap without any perceptible cost, and there is no re-render of the item list. Because the total is derived rather than accumulated, there is no risk of floating-point drift compounding across many interactions — each recalculation starts fresh from the item prices. The sticky bar is positioned with the layout rather than on scroll listeners, so scrolling the summary stays smooth. For a real cart, validate promo codes server-side and debounce the field if you check them as the user types.

Reusing it

Replace the items with your cart data, wire the address and payment rows to your real sources, validate promo codes against your backend, and submit the order on place. Lift it out of the phone frame for a responsive web checkout, or keep it framed after a mini cart to present the full purchase flow.

Build with AI

Build, Understand, Optimize, and Extend It With AI

You do not have to trace the pricing math by hand to trust it. Paste this snippet's HTML, CSS, and JS into an AI coding assistant like Claude and ask it to explain exactly why every interaction routes through the single recalc function instead of nudging a running total, or how the mck-pdot custom radio styling relies on the checked sibling selector to stay in sync with the underlying input. The same assistant can help optimize it — ask whether recalculating from every item's data-price on each stepper tap could become a bottleneck with a large cart, or whether the promo-code check belongs behind a debounce if you validate it against a live endpoint as the user types. It is just as good for extending the feature: have it add a remove-item button that respects the same recalc pipeline, support multiple stacked promo codes, or add a subtle highlight animation when the total changes. Treat the code less like a finished artifact and more like a starting point for a conversation.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a mobile checkout/order-review screen in plain HTML, CSS, and JavaScript inside a phone-frame container — no framework, no state library.

Requirements:
- A delivery-address card, a cart-items card where each item stores its unit price in a data-price attribute and shows a quantity stepper, a payment-method card, a promo-code card, and an order-summary card, followed by a sticky bottom bar showing the total and a place-order button.
- Implement a single recalc function that is the only place totals are computed: it walks every cart item, multiplies its data-price by its current displayed quantity, sums the subtotal, applies a discount rate as a percentage of the subtotal, adds a flat shipping fee, and writes the subtotal, discount line, grand total, and the sticky bar's total from that one calculation, called after every state-changing action.
- Quantity steppers must never let an item's quantity fall below one from the minus button, while the plus button always increments; every stepper click must call recalc.
- The promo-code field must uppercase the entered code before comparison, apply a real percentage discount for one valid code, show a green success message and reveal a previously-hidden discount line for that code, and show a red error message (different wording for empty versus invalid) for anything else, always followed by a recalc call.
- Payment methods must be real, visually hidden radio inputs sharing one name attribute, with a custom circular indicator styled purely through a CSS sibling selector reacting to the checked state, not through JavaScript.
- The place-order button must visually confirm success (label and background color change) when clicked, without a page navigation.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSA checkout renders with an address, two items, payment options, a promo field, and a summary.
  2. 2
    Adjust quantitiesThe plus and minus steppers change item counts and the subtotal and total update instantly.
  3. 3
    Apply a promo codeType SAVE10 and tap Apply — a green discount line appears and the total drops 10%.
  4. 4
    Try an invalid codeAny other code shows a red error and clears the discount.
  5. 5
    Pick a payment methodThe custom radios let only one method be selected.
  6. 6
    Place the orderThe sticky button flips to a green confirmed state.

Real-world uses

Common Use Cases

Ecommerce apps
The final step after a mini cart.
Order review
Pair with an order summary layout.
Payment forms
A mobile take on a checkout form.
Promo entry
Reuse the field like a promo code input.
App mockups
Present it inside a phone mockup.
Learning cart math
A reference for centralized totals and discounts.

Got questions?

Frequently Asked Questions

All figures are written by one recalc() function. It sums each item's data-price times its quantity, applies the discount rate, adds flat shipping, and updates the subtotal, discount line, summary total, and sticky-bar total together. Every interaction calls this one function, so the numbers can never disagree.

The decrement handler only reduces the quantity while it is above one. This is a deliberate guard: dropping to zero from a stepper is ambiguous, so real carts require an explicit remove action instead. To support removal, add a trash button that deletes the item and calls recalc().

SAVE10 applies a 10% discount. The input is upper-cased before comparison so save10 also works. An empty field shows a prompt to enter a code, and any other value shows an invalid-code error and clears the discount. In production you would validate the code against your backend rather than a hard-coded string.

Yes. Each is a hidden radio input grouped by the same name attribute, with a styled dot driven by the :checked ~ sibling selector. Because they are genuine radios, only one can be selected and keyboard and screen-reader users can choose a method without any JavaScript.

Hold the cart items, selected payment, and discount in state, and compute the totals as derived values with useMemo (React), computed (Vue), or a getter (Angular) instead of writing to the DOM. Bind the steppers and promo apply to handlers that update state, and submit the order on place. The CSS and Tailwind utilities port directly.