Embla Carousel Scale-on-Focus (Center Slide Emphasis) — Free Snippet

Embla Carousel Scale-on-Focus (Center Slide Emphasis) · Carousels · Plain HTML, CSS & JS · Live preview

What's included

Features

Continuous scale tween
Scale and opacity follow scroll position.
Centred snaps for every slide
containScroll: false.
Opens on a chosen slide
startIndex centres the popular plan.
Click-to-centre
Side cards come to the centre before acting.
Drag-safe buttons
Embla v8 blocks clicks that end a drag.
Focus follows keyboard
Tabbing centres the focused card.
Announced selection
A polite live region names the centred plan.
No layout shift
Only transform and opacity animate.

About this UI Snippet

Embla Carousel Scale Effect — Emphasising the Centred Slide

Screenshot of the Embla Carousel Scale-on-Focus (Center Slide Emphasis) snippet rendered live

When a carousel shows several items at once, people need to know which one is "current". Scaling the centred slide up and fading its neighbours makes that obvious without any extra UI, and because the effect is tied to scroll position, cards grow and shrink smoothly while you drag rather than switching state at the end.

Distance to centre, mapped to scale

On every scroll event the snippet computes each snap's distance from the current position (scrollSnapList()[i] - scrollProgress()). That distance, multiplied by a tween factor and clamped, becomes t: 1 at the centre, 0 far away. Scale runs from 0.82 to 1 and opacity from 0.45 to 1. It's the same calculation used for parallax, applied to different properties.

Every slide gets its own centred position

By default Embla's containScroll trims snaps at the ends so the carousel never shows empty space, which means the first and last cards can't be centred. containScroll: false gives every card a centred snap. startIndex: 2 opens on the middle "Pro" plan.

Click to centre, then act

Clicking the button on a side card scrolls it to the centre instead of choosing it immediately. Only the centred card's button performs the action. This prevents accidental choices on half-visible cards. Embla v8 already stops the click that ends a drag, so dragging across a button never triggers it.

Keyboard and screen readers

Tabbing to a card's button centres its slide, and the selected plan is announced in a polite live region.

Scale without layout shifts

Only transform and opacity change, so neighbouring cards never reflow while you drag.

Step by step

How to Use

  1. 1
    Load EmblaInclude embla-carousel.umd.js from the CDN.
  2. 2
    Paste the snippetFive plan cards render with Pro centred and enlarged.
  3. 3
    DragCards scale and fade continuously based on their distance from the centre.
  4. 4
    Click a side cardIt moves to the centre; click again to choose it.
  5. 5
    Adjust the lookChange the 0.82 and 0.45 minimums or TWEEN_FACTOR_BASE.

Real-world uses

Common Use Cases

Pricing plans on mobile
Show Free, Pro and Team as swipeable cards where the centred plan grows and brightens. startIndex opens on the popular plan, so the plan you most want to sell is seen first.
Product, size and model pickers
Let shoppers swipe through variants such as models or sizes. The enlarged centre card makes the current choice obvious, and clicking a side card brings it to the centre before anything happens.
Media shelves with a focused item
Browse albums, films or books where one title is always in focus. Neighbours fade by distance from the centre, which makes the selection readable without a separate highlight element.
Onboarding role and goal selection
Ask new users to pick a role or goal from large cards. Because every slide can sit centred (containScroll: false), even the first and last options can reach the middle.
Character and level select screens
Build a game menu where the focused option scales up as you drag. Start the game from the click handler only once a card is already centred.
Related: Embla Parallax Slides
The same tween as parallax: Embla Carousel Parallax Slides.
Related: Pricing Card
A static pricing layout: Pricing Card.

Got questions?

Frequently Asked Questions

On each scroll event, compute each snap's distance from scrollProgress(), convert it into a 0-1 value that is 1 at the centre, and apply it as a CSS scale on the slide's inner element. Apply it to an inner element, not the slide itself, so Embla's measurements stay correct.

The default containScroll setting trims snaps at the start and end so no empty space is shown. Set containScroll to false to give every slide its own centred snap.

Pass startIndex in the options, for example startIndex: 2 to begin on the third slide.

Embla measures slide sizes and positions. Transforming the slide element would interfere with those measurements; transforming a child keeps the layout stable.

No. Embla v8 adds a capture-phase click listener to its container and stops the click that ends a drag, so buttons only respond to real clicks.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Give this snippet to an AI assistant like Claude and ask it to explain how distance to centre becomes scale and opacity, and why containScroll must be false. Ask it to add a 3D rotateY for side cards, a monthly/annual toggle that updates prices, or a highlighted "Most popular" badge on the default card. It can also check the keyboard flow for a pricing page.

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 pricing-plan carousel with Embla Carousel v8 (loaded from a CDN as UMD) in plain HTML, CSS and JavaScript.

Requirements:
- Render five plan cards (name, price, three features, choose button), about 46% wide on phones and 34% on wider screens.
- Center-align slides, disable scroll containment so every card can be centred, and start on the third plan.
- On scroll, compute each snap's distance from the current scroll progress and set each inner card's scale (0.82 to 1) and opacity (0.45 to 1) so the centred card is emphasised, updating only slides in view.
- Clicking the button on a side card scrolls it to the centre; clicking the centred card's button confirms the choice.
- Tabbing to a card's button centres it, and the centred plan is announced in a polite live region.
- Only animate transform and opacity.

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.

Source Code

<div class="esc">
  <h2 class="esc-title">Pick your plan</h2>
  <div class="esc-viewport" id="escViewport">
    <div class="esc-container" id="escContainer"></div>
  </div>
  <p class="esc-hint" id="escHint" aria-live="polite"></p>
</div>