Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Swiper shows one row even though grid rows is set

ErrorSlides show in one row although grid={{ rows: 2 }} is set

Short answer

Swiper React only includes its core. Import Grid from swiper/modules, add it to the modules prop, and import swiper/css/grid. Then set grid rows and a numeric slidesPerView: auto is not compatible when rows is above 1. In loop mode, use an even slide count or loopAddBlankSlides.

  • Applies to Swiper 14, Next.js 15, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the three parts the grid needs: the module in the modules array, its CSS import, and the grid option on the component.

    grep -rn "swiper/modules\|swiper/css\|grid=" app/ components/
  2. 2Match what you see, then jump to its fix

    1. 1The grid prop has no visible effect.The Grid module or its CSS is not loadedFix
    2. 2Rows are broken as soon as grid.rows is above 1 and slidesPerView is 'auto'.slidesPerView is set to autoFix
    3. 3Loop is on together with a grid, and the slide count is odd.Loop mode with an odd number of slidesFix
    4. 4The first slides run down the columns rather than across the rows.Slides fill by column and the order looks wrongFix

What does the error look like?

  • Slides show in one row although grid={{ rows: 2 }} is set
  • Rows break as soon as slidesPerView is 'auto' and grid rows is above 1
  • Slides run down the columns instead of across the rows

Cause 1 of 4

The Grid module or its CSS is not loaded

1Check

Swiper React uses only the core version by default, and each module must be added through the modules prop. The grid styles live in swiper/css/grid.

grep -rn "Grid" components/ app/ | grep -i swiper

2Fix

Import Grid and its styles, then pass the module in modules.

import { Swiper, SwiperSlide } from 'swiper/react'
import { Grid } from 'swiper/modules'
import 'swiper/css'
import 'swiper/css/grid'

<Swiper modules={[Grid]} slidesPerView={3} grid={{ rows: 2, fill: 'row' }}>
  <SwiperSlide>1</SwiperSlide>
  {/* more slides */}
</Swiper>

3Verify

Reload: slides now fill two rows.

npm run dev

Confirmed by swiperjs.com

Did this fix it?

Cause 2 of 4

slidesPerView is set to auto

1Check

Swiper documents that slidesPerView: 'auto' is not compatible with multirow mode when grid.rows is greater than 1.

grep -rn "slidesPerView" components/ app/

2Fix

Use a number for slidesPerView, or per breakpoint through the breakpoints parameter.

<Swiper modules={[Grid]} slidesPerView={2} grid={{ rows: 2 }}>

3Verify

Check the layout at your main screen widths.

npm run dev

Confirmed by swiperjs.com

Did this fix it?

Cause 3 of 4

Loop mode with an odd number of slides

1Check

Swiper notes that with loop mode the slide count must be even, or loopAddBlankSlides must be enabled. Count your slides.

grep -rn "loop" components/ app/ | grep -i swiper

2Fix

Make the slide count even, or set loopAddBlankSlides on the Swiper.

<Swiper modules={[Grid]} loop loopAddBlankSlides slidesPerView={2} grid={{ rows: 2 }}>

3Verify

Scroll through to the end and check the last slide.

npm run dev

Confirmed by swiperjs.com

Did this fix it?

Cause 4 of 4

Slides fill by column and the order looks wrong

1Check

The grid fill option is column by default. It can be 'column' or 'row' and decides how slides fill rows.

grep -rn "fill" components/ app/ | grep -i grid

2Fix

Set fill to row when you want a left-to-right reading order.

grid={{ rows: 2, fill: 'row' }}

3Verify

The first slides now run across the first row.

npm run dev

Confirmed by swiperjs.com

Did this fix it?

How do I stop it coming back?

  • Every time you use a Swiper feature, check its module name and CSS file in the API page.
  • Use numeric slidesPerView when a grid is involved.
  • Keep the slide count even if the carousel is a looping grid.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

next/link throws React.Children.only on its children

Error: React.Children.only expected to receive a single React element child.

React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.

3 causes, each with a fix

Web apps

Hydration failed after adding next-themes dark mode

Console reports a server and client mismatch on the html element

next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.