CSS Previous Next Post Links

Previous and next article links as two cards with titles and arrows, for the end of blog posts.

  • pagination
  • blog
  • article
  • rel prev
  • next post
HTML
<nav class="post-nav" aria-label="More posts">
  <a class="post-nav-prev" href="#" rel="prev">
    <span>Previous</span>
    Getting started with Grid
  </a>
  <a class="post-nav-next" href="#" rel="next">
    <span>Next</span>
    Mastering flex gaps
  </a>
</nav>
CSS
.post-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  font: 600 14px/1.35 system-ui, sans-serif;
}

.post-nav a {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid #e7e5e4;
  border-radius: 12px;
  background: #ffffff;
  color: #1c1917;
  text-decoration: none;
  transition: border-color 0.2s ease;
}

.post-nav a:hover {
  border-color: #1c1917;
}

.post-nav a:focus-visible {
  outline: 2px solid #ea580c;
  outline-offset: 2px;
}

.post-nav span {
  color: #78716c;
  font-size: 12px;
  font-weight: 500;
}

.post-nav-prev span::before {
  content: "← ";
  content: "← " / "";
}

.post-nav-next {
  text-align: right;
}

.post-nav-next span::after {
  content: " →";
  content: " →" / "";
}

About this CSS Previous Next Post Links

This CSS Previous Next Post Links is 47 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses transitions, CSS Grid and keyboard focus styles. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #e7e5e4
  • #ffffff
  • #1c1917
  • #ea580c
  • #78716c

How to use this previous next post links

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .post-nav class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback