Setting Up Jekyll Pagination for Blog Posts
Learn how to enable Jekyll pagination, configure the paginate gem, edit your index layout, verify generated pages, and roll back if needed.
07 Jul 2025, 18:03 UTC

Desired outcome
Enable pagination so that blog posts are split across multiple pages (e.g., index.html, page2/index.html, …) with navigation links that work correctly.
Prerequisites
- Jekyll 4.x or later installed (the pagination feature is provided by the
jekyll-paginategem). - A Jekyll site with a
_config.ymlfile and a layout or page that will act as the index (commonlyindex.htmlin the site root). - Basic familiarity with editing YAML and Liquid templates.
- Access to the site’s repository or local working copy with write permissions.
Procedure
- Add the pagination gem
Open the site’s
Gemfile(create one if it does not exist) and ensure the following line is present:gem 'jekyll-paginate'Run Bundler to install the gem:
# Run in the site root directory bundle installRequired permissions: write access to the Gemfile and ability to execute
bundle installin the project directory.Risk: If the gem version conflicts with other dependencies, Bundler will report an error; resolve by updating the Gemfile or using
bundle update. - Enable pagination in
_config.ymlAdd or modify these lines:
# Number of posts per page paginate: 5 # Ensure the plugin is loaded plugins: - jekyll-paginateThe
paginatevalue can be any positive integer; adjust to suit your design. - Create or edit the index layout
If you do not already have an
index.html(or a layout used as the home page), create it in the site root. Insert the following Liquid markup:<!-- index.html --> <ul> {% for post in paginator.posts %} <li> <a href="{{ post.url }}">{{ post.title }}</a> <p>{{ post.date | date: "%b %d, %Y" }}</p> </li> {% endfor %} </ul> <!-- Pagination navigation --> {% if paginator.total_pages > 1 %} <nav> {% if paginator.previous_page %} <a href="{{ paginator.previous_page_path }}">« Newer posts</a> {% endif %} {% if paginator.next_page %} <a href="{{ paginator.next_page_path }}">Older posts »</a> {% endif %} <nav> {% endif %}This loop displays the paginated posts and adds “Newer posts” / “Older posts” links using the
paginatorobject’s paths. - Verify ordering (optional but recommended)
Ensure posts are sorted newest‑first. By default Jekyll sorts
site.postsby date descending, but you can enforce it in_config.yml:defaults: - scope: path: "" type: posts values: layout: "post" # No extra sort needed; default is date descending. - Build and serve the site
Run Jekyll locally to generate the paginated output:
# Development server with auto‑reload bundle exec jekyll serve # Or a one‑off build bundle exec jekyll buildThe command should be executed in the site root with the same user that owns the project files.
Expected checks
- After
jekyll build, inspect the generated_sitedirectory. You should see files such as: _site/index.html(first page)_site/page2/index.html,_site/page3/index.html, … up to_site/pageN/index.htmlwhereN = ceil(total_posts / paginate).- Open
_site/index.htmlin a browser and confirm that the number of post listings matches thepaginatevalue. - Click the “Older posts” link; the browser should load
_site/page2/index.htmland display the next set of posts. - On the first page, the “Newer posts” link should be absent; on the last page, the “Older posts” link should be absent.
- Run an HTML validation tool such as
htmlprooferto catch broken pagination links:
bundle exec htmlproofer ./_site
A successful run reports zero errors related to pagination.
Recovery options
If pagination produces unexpected results or you wish to disable it:
- Remove or comment out the
paginate:line and thejekyll-paginateentry fromplugins:in_config.yml. - Optionally, delete the pagination navigation block from
index.html(or restore a backup of the file). - Re‑run
jekyll buildorjekyll serveto regenerate the site without paginated pages. - Verify that only
_site/index.htmlexists and that all posts appear on that single page.
Limitations
- The built‑in pagination only applies to the default
postscollection. To paginate a different collection (e.g.,projects), you must add apaginate_collectionsetting in_config.yml:
paginate_collection: "projects"
jekyll build --incremental; a full build is required after any change to _config.yml or the index layout.0 replies
A thoughtful contribution can make all the difference. Be the first to share one.