New Launch

Take a deep dive into the fastest Gatsby, yet: Gatsby 5!

Adding Pagination

A page displaying a list of content gets longer as the amount of content grows. Pagination is the technique of spreading that content across multiple pages.

The goal of pagination is to create multiple pages (from a single template) that show a limited number of items.

Each page will query GraphQL for those specific items.

The information needed to query for those specific items (i.e. values for limit and skip) will come from the context that is added when creating pages in gatsby-node.


The code above will create a number of pages based on the total number of posts. Each page will list postsPerPage(6) posts, until there are less than postsPerPage(6) posts left. The path for the first page is /blog, following pages will have a path of the form: /blog/2, /blog/3, etc.

Other resources

Edit this page on GitHub
© 2022 Gatsby, Inc.