CSS Compact Pagination
A small pager that shows "Page 2 of 9" between previous and next arrows, ideal for mobile.
<nav class="compact-pager" aria-label="Pagination">
<a href="#" aria-label="Previous page">‹</a>
<span>Page <b>2</b> of 9</span>
<a href="#" aria-label="Next page">›</a>
</nav>
.compact-pager {
display: inline-flex;
align-items: center;
overflow: hidden;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 0 0 1px #e2e8f0;
color: #475569;
font: 500 14px system-ui, sans-serif;
}
.compact-pager span {
padding: 0 16px;
border-inline: 1px solid #e2e8f0;
line-height: 40px;
}
.compact-pager b {
color: #0f172a;
}
.compact-pager a {
display: grid;
place-items: center;
width: 40px;
height: 40px;
color: #0f172a;
font-size: 22px;
text-decoration: none;
}
.compact-pager a:hover {
background: #f1f5f9;
}
.compact-pager a:focus-visible {
outline: 2px solid #2563eb;
outline-offset: -2px;
}
/* Add aria-disabled="true" on the first and last page */
.compact-pager [aria-disabled="true"] {
color: #cbd5e1;
pointer-events: none;
}
About this CSS Compact Pagination
This CSS Compact Pagination is 45 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses box shadows, CSS Grid, Flexbox 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:
#ffffff#e2e8f0#475569#0f172a#f1f5f9#2563eb#cbd5e1
How to use this compact pagination
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.compact-pagerclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein 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.