Skip to main content

Pagination

In Turkish
Sayfalama
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/pagination

In short

Pagination is the practice of splitting a large set of results into smaller pages, so an API or website returns a manageable number of items per request.

What is pagination?

Pagination divides a long list of results, such as products, search hits, or messages, into smaller chunks called pages. Instead of returning a million rows at once, which would be slow and use a huge amount of memory, an API returns, say, 20 items along with a way to ask for the next 20. The same idea powers numbered page links, 'Load more' buttons, and infinite scrolling in user interfaces.

The two most common techniques are offset and cursor pagination. Offset pagination uses parameters like ?limit=20&offset=40 or ?page=3 and maps directly to SQL's LIMIT and OFFSET, which makes it easy to build and lets users jump to any page. Cursor pagination returns a token that points to the last item seen, like ?cursor=abc123, and the next request continues right after that item.

Offset pagination has two drawbacks on large or fast-changing data: the database still has to read and skip every row before the offset, so deep pages get slow, and items can be skipped or repeated when rows are added or deleted between requests. Cursor pagination, called keyset pagination when the cursor is a column value such as an ID or timestamp, avoids both problems by using an index to jump straight to the right place. Its trade-off is that you can't jump directly to page 50.

A good analogy is reading a long book: offset pagination is like saying 'go to page 50', while cursor pagination is like placing a bookmark and continuing from it. APIs usually describe how to get the next page in the response, with a nextCursor field, a hasMore flag, or a Link header, and they cap the page size so clients can't request everything at once.

Key takeaways

  • Pagination returns large result sets in smaller pages.
  • Offset pagination (limit and offset) is simple and allows jumping to any page.
  • Cursor pagination continues after the last item seen and stays fast on large tables.
  • Offset pagination can skip or repeat items when data changes between requests.
  • APIs should cap the page size and tell clients how to fetch the next page.

Example

Offset and cursor pagination in SQLsql
-- Offset pagination: page 3 with 20 items per page (skips 40 rows)
SELECT id, title FROM posts
ORDER BY id
LIMIT 20 OFFSET 40;

-- Cursor (keyset) pagination: the next 20 items after the last id seen (1040)
SELECT id, title FROM posts
WHERE id > 1040
ORDER BY id
LIMIT 20;

Readers ask

What is the difference between offset and cursor pagination?

Offset pagination asks for items by position, such as skip 40 and take 20, while cursor pagination asks for the items that come after a specific item. Offset is simpler and supports page numbers; cursor is faster on large datasets and doesn't skip or repeat items when data changes.

How many items should an API return per page?

Common defaults are 20 to 100 items, with a maximum the client cannot exceed. The right size balances response time and payload size against how many requests clients need to make.

Is infinite scroll a type of pagination?

Yes. Infinite scroll is a user interface that loads the next page automatically as the user nears the end of the list, and behind the scenes it usually relies on cursor pagination.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings