Swiper shows one row even though grid rows is set
Slides show in one row although grid={{ rows: 2 }} is setShort 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.
Fix it fast
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/2Match what you see, then jump to its fix
- 1
The grid prop has no visible effect.The Grid module or its CSS is not loadedFix - 2
Rows are broken as soon as grid.rows is above 1 and slidesPerView is 'auto'.slidesPerView is set to autoFix - 3
Loop is on together with a grid, and the slide count is odd.Loop mode with an odd number of slidesFix - 4
The first slides run down the columns rather than across the rows.Slides fill by column and the order looks wrongFix
- 1
What does the error look like?
Slides show in one row although grid={{ rows: 2 }} is setRows break as soon as slidesPerView is 'auto' and grid rows is above 1Slides 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 swiper2Fix
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 devConfirmed by swiperjs.com
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 devConfirmed by swiperjs.com
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 swiper2Fix
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 devConfirmed by swiperjs.com
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 grid2Fix
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 devConfirmed by swiperjs.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb 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 fixWeb 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