Options

Embla Carousel takes various options in order to customize how the carousel works.


Usage

You can provide options in two different ways: With the constructor options and/or global options. If both are provided, they will be merged, and if any options are in conflict, the constructor option has precedence and will override global options.

Constructor options

The constructor options is the default way of providing options to Embla Carousel. In the following example, the carousel loop option is set to true:

import EmblaCarousel from 'embla-carousel'
const emblaNode = document.querySelector('.embla')const emblaApi = EmblaCarousel(emblaNode, { loop: true })

Note that it's possible to change options passed to the Embla Carousel constructor after initialization with the reInit method.

Global options

Setting global options will be applied to all carousels which will override the Embla default options with your own. In the following example loop is set to true:

import EmblaCarousel from 'embla-carousel'
EmblaCarousel.globalOptions = { loop: true }
const emblaNode = document.querySelector('.embla')const emblaApi = EmblaCarousel(emblaNode, { align: 'start' })

Make sure to assign global options before initializing any carousel and only assign it once. Re-assigning global options might lead to confusing code and unexpected behaviour.

TypeScript

The EmblaOptionsType is obtained directly from the core package embla-carousel and used like so:

import EmblaCarousel, { EmblaOptionsType } from 'embla-carousel'
const emblaNode = document.querySelector('.embla')const options: EmblaOptionsType = { loop: true }const emblaApi = EmblaCarousel(emblaNode, options)

Reference

Below follows an exhaustive list of all Embla Carousel options and their default values.


active

Type: boolean
Default: true

Setting this to false will not activate or deactivate the carousel. Useful when used together with the breakpoints option to toggle the carousel active/inactive depending on media queries.


align

Type: string | (viewSize: number, snapSize: number, index: number) => number
Default: center

Align the slides relative to the carousel viewport. Use one of the predefined alignments start, center or end. Alternatively, provide your own callback to fully customize the alignment.


axis

Type: string
Default: x

Choose scroll axis between x and y. Remember to stack your slides horizontally or vertically using CSS to match this option.


breakpoints

Type: EmblaOptionsType
Default: {}

An object with options that will be applied for a given breakpoint by overriding the options at the root level. Example: '(min-width: 768px)': { loop: false }.

Note: If multiple queries match, they will be merged. And when breakpoint options clash, the last one in the list has precedence.


container

Type: string | HTMLElement | null
Default: null

Enables choosing a custom container element which holds the slides. By default, Embla will choose the first direct child element of the root element. Provide either a valid CSS selector string or a HTML element.


containScroll

Type: falsestring
Default: 'trimSnaps'

Clear leading and trailing empty space that causes excessive scrolling. Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.

Note: When this is active, it will override alignments applied by the align option for enough slides at the start and the end of the carousel, in order to cover the leading and trailing space.


direction

Type: string
Default: ltr

Choose content direction between ltr and rtl.

Note: When using rtl, the content direction also has to be set to RTL, either by using the HTML dir attribute or the CSS direction property.


dragFree

Type: boolean
Default: false

Enables momentum scrolling. The duration of the continued scrolling is proportional to how vigorous the drag gesture is.


dragThreshold

Type: number
Default: 10

Drag threshold in pixels. This only affects when clicks are fired and not. In contrast to other carousel libraries, it will not affect when dragging of the carousel starts.

Note: Browsers handle touch events differently than mouse events. Browsers won't fire the click event when a touch event includes an accidental slight swipe gesture. This is why this threshold only works for mouse events.


duration

Type: number
Default: 25

Set scroll duration when triggered by any of the API methods. Higher numbers enables slower scrolling. Drag interactions are not affected because duration is then determined by the drag force.

Note: Duration is not in milliseconds because Embla uses an attraction physics simulation when scrolling instead of easings. Only values between 20-60 are recommended.


inViewThreshold

Type: IntersectionObserverInit.threshold
Default: 0

This is the Intersection Observer threshold option that will be applied to all slides.


loop

Type: boolean
Default: false

Enables infinite looping. Embla will apply translateX or translateY to the slides that need to change position in order to create the loop effect.

Embla automatically falls back to false if slide content isn't enough to create the loop effect without visible glitches.


skipSnaps

Type: boolean
Default: false

Allow the carousel to skip scroll snaps if it's dragged vigorously. Note that this option will be ignored if the dragFree option is set to true.


slides

Type: string | HTMLElement[] | NodeListOf<HTMLElement> | null
Default: null

Enables using custom slide elements. By default, Embla will choose all direct child elements of its container. Provide either a valid CSS selector string or a nodeList/array containing HTML elements.

Note: Even though it's possible to provide custom slide elements, they still have to be direct descendants of the carousel container.

Warning: If you place elements inside the carousel container that aren't slides, they either shouldn't have any size, or should be detached from the document flow with position: absolute or similar.


slidesToScroll

Type: string | number
Default: 1

Group slides together. Drag interactions, dot navigation, and previous/next buttons are mapped to group slides into the given number, which has to be an integer. Set it to auto if you want Embla to group slides automatically.


startIndex

Type: number
Default: 0

Set the initial scroll snap to the given number. First snap index starts at 0. Please note that this is not necessarily equal to the number of slides when used together with the slidesToScroll option.


watchDrag

Type: boolean | (emblaApi: EmblaCarouselType, event: MouseEvent | TouchEvent) => boolean | void
Default: true

Enables for scrolling the carousel with mouse and touch interactions. Set this to false to disable drag events or pass a custom callback to add your own drag logic.

Note: When passing a custom callback it will run before the default Embla drag behaviour. Return true in your callback if you want Embla to run its default drag behaviour after your callback, or return false if you want to disable it.


watchResize

Type: boolean | (emblaApi: EmblaCarouselType, entries: ResizeObserverEntry[]) => boolean | void
Default: true

Embla automatically watches the container and slides for size changes and runs reInit when any size has changed. Set this to false to disable this behaviour or pass a custom callback to add your own resize logic.

Note: When passing a custom callback it will run before the default Embla resize behaviour. Return true in your callback if you want Embla to run its default resize behaviour after your callback, or return false if you want to disable it.


watchSlides

Type: boolean | (emblaApi: EmblaCarouselType, mutations: MutationRecord[]) => boolean | void
Default: true

Embla automatically watches the container for added and/or removed slides and runs reInit if needed. Set this to false to disable this behaviour or pass a custom callback to add your own slides changed logic.

Note: When passing a custom callback it will run before the default Embla mutation behaviour. Return true in your callback if you want Embla to run its default mutation behaviour after your callback, or return false if you want to disable it.


Edit this page on GitHub