Skip to the content

Pricing toggle

A pricing table of two, three or more plans with a monthly or yearly switch, and the switch is a crank.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    The look of the preview is the pricing-toggle-* classes: the switch, its knob and the two words inside it, the plates of the plans. What moves is in the Embed. Its accent is the color setting; the ink of the focus ring and the ground a hovered button takes are two variables, --pricing-toggle-ink and --pricing-toggle-ground, to set on the section in a rule of your own. A price is kept on one line and asked for tabular figures, so nothing moves sideways while it turns. The switch is a Link block, because Webflow has no button element: the Embed keeps a click on it in place and lets Space press it.
  3. Add custom JS

  4. Tune it

    Custom attributes
    Select the section on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-pricing-toggle Marks the block that holds the switch and the plans: the section of the paste, or any box of your own. It takes no value: leave the value field empty. The settings below go on the same element.
    data-pricing-toggle-switch On the switch, the element that is pressed and dragged. It takes no value. The engine gives it role="switch" when it has no role, writes aria-checked on it and names it after the word of the yearly side. Without it nothing can be pressed, and the console says so. [ Required ]
    data-pricing-toggle-price On each price, with its two values beside it: data-pricing-toggle-monthly="$49" and data-pricing-toggle-yearly="$490", written the way they should read, currency and separators included. The price rolls digit by digit. Left without data-pricing-toggle-monthly, the text of the element is the monthly value. The text is also what a page without JavaScript shows. [ Required ]
    data-pricing-toggle-yearly The yearly value. On a price it sits beside data-pricing-toggle-price. Alone on any other element, a word, a line, it gives that text its yearly version, "per year" for "per month", and the whole text turns as one. Without it on any element of the block, nothing changes with the switch. [ Required ]
    data-pricing-toggle-label On the visible word of each side, with the value monthly or yearly, inside the switch or beside it. A click on it sets that side, the one not chosen steps back, and the yearly one names the switch for a screen reader. [ Optional ]
    data-pricing-toggle-knob On the knob inside the switch. It takes no value. Without one the engine adds a span, which then needs a size and a colour of your own. [ Optional ]
    data-pricing-toggle-yearly-href On a link, with its address on the yearly side as the value, the yearly checkout page of the plan for one. Its href is the monthly one, unless data-pricing-toggle-monthly-href gives another. [ Optional ]
    data-pricing-toggle-show On what is there on one side only, with the value yearly or monthly: a note, a badge. It keeps its room on the other side, unseen, so nothing jumps. [ Optional ]
    data-pricing-toggle-plan On the box of a plan. Its heading, or the value of the attribute when it has one, is the name said before the price when the new prices are read to a screen reader. [ Optional ]
    data-pricing-toggle-cta On the button of a plan: the hover of the preview, the button takes the accent. With the value usual, for the button already in the accent, it takes the ground instead. [ Optional ]
    data-pricing-toggle-period Written by the engine on the block: monthly or yearly. Never written by hand; a style of your own can read it. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same section. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-pricing-toggle-color #ffab1a The accent: the colour that fills the track of the switch as the knob reaches the yearly side, and the one a plan's button takes under the pointer. Options: any CSS colour. The engine writes it on the block as --pricing-toggle-color.
    data-pricing-toggle-duration 1.6 Seconds the prices take to cross from one side to the other after a click or a key, leaving slowly and settling slowly. A drag is not timed: the prices stay under the hand.
    data-pricing-toggle-spread 0.72 Share of the travel over which the columns leave one after the other, from 0 to 0.9.
    data-pricing-toggle-start monthly The period shown when the page arrives. Options: monthly or yearly. Without JavaScript the page shows the monthly side whatever this says.
    data-pricing-toggle-remember false Keeps the period the visitor chose, in the browser's local storage, and shows it on the next visit instead of start. Options: true or false. One choice for the whole site: every table that remembers reads the same one.
    data-pricing-toggle-drag true Whether the knob may be dragged. Options: true or false. At false the switch only answers a click and the keyboard, and the prices still follow the knob.
    data-pricing-toggle-announce true Says the new prices once to a screen reader after a change, as one sentence: the word of the side, then each plan and its price. Options: true or false. At false the switch still says its state and each price still reads as its current value.

What it does

Pricing toggle is a site utility component for Webflow and vanilla JavaScript, with no library. Also called monthly yearly pricing toggle, monthly annual pricing toggle or pricing table toggle.

A pricing table of two, three or more plans with a monthly or yearly switch, and the switch is a crank. Its knob can be dragged: the prices are geared to it, so they turn while the hand moves, stop when it stops, and fall back if it lets go before the middle. A click, Space, Enter or the arrow keys send the knob to a side and the prices cross after it, unhurried, leaving slowly and settling slowly, so there is time to watch the figures turn. Each price is cut in columns, units under units: a column whose digit changes is a wheel that takes the short way round, a mark both values share never moves, and a column only one value has opens or closes, so a price that gains a digit glides wider instead of jumping. The columns leave one after the other in the order of the page, a wave that crosses the table. What depends on the period follows in the same wave: the word "per month", a line under the price, a note that is there on the yearly side only, the link of each plan's button. Both prices are written as attributes, currency and separators included. The switch is a real one, role switch, named by its yearly word; a screen reader hears the new prices once, in a sentence, never the digits going by. Without JavaScript the page shows the monthly prices. Under reduced motion the values swap with no roll. No library. Pattern type pricing toggle, billing switch, price counter.

Updated

Questions

Add the custom attribute data-pricing-toggle to the section, data-pricing-toggle-switch to the switch, and on each price data-pricing-toggle-price with data-pricing-toggle-monthly and data-pricing-toggle-yearly holding the two prices. The paste already carries all of them; on the canvas the section shows its monthly side and every text stays editable.

Write both values exactly as they should read, data-pricing-toggle-monthly="1 290,00 €" and data-pricing-toggle-yearly="12 900,00 €". The engine never formats a number: it sets the two values units under units, turns the digits that differ and leaves the marks they share in place.

Yes. The switch carries role="switch" and aria-checked, takes Space, Enter and the arrow keys, and is named by the word of its yearly side. After a change the new prices are said once as a sentence, each plan then its price, and the rolling digits are hidden from the screen reader; data-pricing-toggle-announce="false" turns the sentence off.

Yes. A link takes data-pricing-toggle-yearly-href with its yearly address and keeps its href for the monthly one. Any text takes data-pricing-toggle-yearly with its yearly version, "per year" for "per month", and data-pricing-toggle-show="yearly" marks what is there on the yearly side only, a "two months free" note for one.

It needs no library: two springs and one requestAnimationFrame clock that only runs while something moves. data-pricing-toggle-remember="true" keeps the chosen period in local storage and shows it at once on the next visit, and data-pricing-toggle-start="yearly" opens the table on the yearly side.