Skip to main content

Default Index

The defaultIndex option sets the index of the panel to display on initialization. Specified as a 0-based index.

import Flicking from "@egjs/flicking";
import "@egjs/flicking/dist/flicking.css";
import "./styles.css";

// defaultIndex: 0 (default)
new Flicking("#flick-first", {
  defaultIndex: 0,
  align: "center"
});

// defaultIndex: 2
new Flicking("#flick-middle", {
  defaultIndex: 2,
  align: "center"
});

// defaultIndex: 4 (last)
new Flicking("#flick-last", {
  defaultIndex: 4,
  align: "center"
});

Summary

Key Options

OptionTypeDefaultDescription
defaultIndexnumber0Initial active panel index (0-based)

Comparison by Value

ValueBehaviorSuitable For
0Starts at the first panel (default)General carousels
nStarts at the (n+1)th panelNavigating directly to a specific panel, deep linking
last indexStarts at the last panelReverse browsing, showing newest items first

Details

How defaultIndex Works

When Flicking is initialized (init()), it moves to the panel at the specified index. The panel is displayed immediately without animation.

// Start at the first panel (default)
defaultIndex: 0

// Start at the third panel
defaultIndex: 2

// Start at the last panel (when there are 5 panels)
defaultIndex: 4
  • Relationship with circular: defaultIndex works correctly even with circular: true. The specified panel becomes the initial active panel.
  • Relationship with align: When used with align: "center", the initial panel is positioned at the center.

Use Cases

When to use?
  • defaultIndex: 0: General sequential browsing carousels
  • Specific index: Sharing a specific slide via URL parameters (deep linking), restoring previous state
  • Last index: UI that shows the newest items first, chat/feed

Notes

Index range

If you specify an index larger than the number of panels, it moves to the last panel. Negative indices may be treated as the first panel.