Core Concepts
Understanding how SwiperFlow works
Understanding how SwiperFlow works will help you build more effective sliders.
How SwiperFlow Works
SwiperFlow uses a declarative, attribute-based system:
- Add structure attributes to your HTML elements to identify the slider components
- Add configuration attributes to customize the slider behavior
- SwiperFlow handles the rest — it automatically initializes and configures Swiper based on your attributes
When the page loads, SwiperFlow scans the DOM for elements with data-swf-component, parses all the data-swf-* attributes, and creates Swiper instances with the corresponding configuration.
The Attribute Prefix
All SwiperFlow attributes use the data-swf- prefix:
data-swf-component="identifier"— Marks the slider container with a unique identifier (required)data-swf-element— Identifies structural elementsdata-swf-loop,data-swf-speed, etc. — Configuration options
Element Hierarchy
data-swf-component="my-slider" (Container)
└── data-swf-element="wrapper" (Wrapper)
└── data-swf-element="list" (Slides Container) ← Configuration goes here
├── data-swf-element="item" (Slide)
├── data-swf-element="item" (Slide)
└── data-swf-element="item" (Slide)Element Roles
| Element | Attribute | Purpose |
|---|---|---|
| Container | data-swf-component="identifier" | Root element with a unique identifier (required). Used for JavaScript API access |
| Wrapper | data-swf-element="wrapper" | Direct child of container, wraps the slides. Swiper uses this for overflow handling |
| List | data-swf-element="list" | Contains all slides. All configuration attributes go on this element |
| Item | data-swf-element="item" | Individual slide. Add your content inside these |
Alternative Element Names
The wrapper element accepts these aliases:
data-swf-element="wrapper"(default)data-swf-element="wrap"data-swf-element="container"
Configuration Placement
All configuration attributes go on the list element, not the component or wrapper.
<!-- ✓ Correct -->
<div data-swf-component="my-slider">
<div data-swf-element="wrapper">
<div data-swf-element="list" data-swf-loop="true" data-swf-gap="20">
...
</div>
</div>
</div>
<!-- ✗ Wrong - attributes on wrong element -->
<div data-swf-component="my-slider" data-swf-loop="true">
...
</div>Navigation & Pagination
Navigation and pagination elements are optional and placed outside the wrapper, but inside the component:
<div data-swf-component="testimonials">
<div data-swf-element="wrapper">
<div data-swf-element="list">
<!-- slides -->
</div>
</div>
<!-- Navigation arrows -->
<div data-swf-element="navigation">
<div data-swf-element="prev-arrow">←</div>
<div data-swf-element="next-arrow">→</div>
</div>
<!-- Pagination dots -->
<div data-swf-element="pagination">
<div data-swf-element="pagination-dot"></div>
</div>
</div>Navigation Elements
| Element | Attribute | Purpose |
|---|---|---|
| Navigation Container | data-swf-element="navigation" | Wraps the arrow buttons |
| Previous Arrow | data-swf-element="prev-arrow" | Triggers slide to previous |
| Next Arrow | data-swf-element="next-arrow" | Triggers slide to next |
Pagination Elements
| Element | Attribute | Purpose |
|---|---|---|
| Pagination Container | data-swf-element="pagination" | Wraps the pagination dots |
| Pagination Dot | data-swf-element="pagination-dot" | Template for pagination bullets |
The pagination dot element serves as a template. SwiperFlow uses its class name and creates clones for each slide.
CSS Classes
SwiperFlow uses your existing CSS classes and adds behavior:
- Slide items use the first class from
data-swf-element="item"elements as the slide class - Active slide receives
swiper-slide-activeby default (customizable viadata-swf-active-class) - Active pagination dot receives
is-activeclass
Automatic Initialization
SwiperFlow automatically initializes on DOMContentLoaded. You can also:
- Manually reinitialize: Call
window.swiperflow.init()after DOM changes - Prevent initialization: Add
data-swf-disabledto the list element - Conditional initialization: Use
data-swf-init="mobile"to only initialize at specific breakpoints
Breakpoints
SwiperFlow uses these viewport breakpoints:
| Breakpoint | Width Range |
|---|---|
| Desktop | ≥ 992px |
| Tablet | 569px – 991px |
| Mobile | 320px – 568px |
Use data-swf-bp-desktop, data-swf-bp-tablet, and data-swf-bp-mobile to set different slides per view at each breakpoint.