webdevpuneet.com

Bootstrap Blog Post Card Grid with Read-Time Sort — Free Snippet

Bootstrap Blog Post Card Grid with Read-Time Filter · Cards · Plain HTML, CSS & JS · Live preview

CategoryCards

Copy & paste

Source Code

<div class="container py-5">
  <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-4">
    <h1 class="bsblog-title mb-0">From the blog</h1>
    <select class="form-select form-select-sm" style="width:auto" id="bsblogSort">
      <option value="newest">Newest first</option>
      <option value="quickest">Quickest read</option>
    </select>
  </div>
  <div class="row g-4" id="bsblogGrid">
    <div class="col-md-4" data-date="2026-09-01" data-mins="8">
      <div class="card h-100"><div class="bsblog-cover" style="--h:230"></div><div class="card-body">
        <span class="badge bg-primary-subtle text-primary-emphasis mb-2">Engineering</span>
        <h5 class="card-title">Scaling our API to 10x traffic</h5>
        <p class="text-muted small">Sep 1 · 8 min read</p>
      </div></div>
    </div>
    <div class="col-md-4" data-date="2026-08-20" data-mins="3">
      <div class="card h-100"><div class="bsblog-cover" style="--h:20"></div><div class="card-body">
        <span class="badge bg-success-subtle text-success-emphasis mb-2">Product</span>
        <h5 class="card-title">Introducing dark mode</h5>
        <p class="text-muted small">Aug 20 · 3 min read</p>
      </div></div>
    </div>
    <div class="col-md-4" data-date="2026-08-28" data-mins="5">
      <div class="card h-100"><div class="bsblog-cover" style="--h:150"></div><div class="card-body">
        <span class="badge bg-warning-subtle text-warning-emphasis mb-2">Design</span>
        <h5 class="card-title">Redesigning our onboarding flow</h5>
        <p class="text-muted small">Aug 28 · 5 min read</p>
      </div></div>
    </div>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 card grid, loaded from the actual CDN
Genuine DOM reordering on sort — appendChild moves real elements, not a CSS-order illusion
Sorts by real per-card metadata (date, read-time minutes) stored as data attributes
Bootstrap 5.3's "subtle" badge variants used for category tags
CSS-gradient cover images, no photography required to try the snippet
Scales to any number of posts with no changes to the sort logic

About this UI Snippet

Bootstrap Blog Post Card Grid with Read-Time Sort — HTML, CSS & JavaScript

Screenshot of the Bootstrap Blog Post Card Grid with Read-Time Filter snippet rendered live

Each card in this grid carries its real metadata as data attributes — data-date and data-mins — so the sort dropdown can genuinely reorder them: Array.from(grid.children) reads every card, .sort() compares dates or read-time minutes depending on the selected option, and grid.appendChild(col) in the new order physically moves each card to its sorted position, since re-appending an element already in the DOM relocates it rather than duplicating it.

Built on real Bootstrap 5.3 cards and grid, with Bootstrap 5.3's newer "subtle" badge variants for the category tags — soft enough not to compete visually with the headline, which is exactly what a category label on a card should do.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads three post cards in their authored order.
  2. 2
    Select "Newest first"The cards reorder so the Sep 1 post leads, followed by Aug 28, then Aug 20.
  3. 3
    Select "Quickest read"The cards reorder again — the 3-minute post leads, then 5-minute, then 8-minute.
  4. 4
    Add a fourth postCopy a column block with its own data-date and data-mins — it participates in both sort orders automatically.

Real-world uses

Common Use Cases

Blog index and article listing pages
Letting readers sort by newest or by how much time they have is a small but genuinely useful piece of content-discovery UX.
Learning real DOM reordering vs. CSS order
A clear example of appendChild repositioning existing elements, the correct approach when sort needs to affect actual tab/reading order too.
Documentation and changelog listings
Reuse the same pattern to sort docs pages by recency or changelog entries by category.
Content hubs with multiple content types
Extend the data attributes to sort by content type, popularity, or any other metadata a card carries.

Got questions?

Frequently Asked Questions

It genuinely reorders the underlying DOM elements — grid.appendChild(col) on an element already in the DOM moves it to the new position rather than creating a duplicate, so the real element order (and therefore tab order for keyboard users) changes too.

Each card's data-mins attribute holds its read-time in minutes; the sort compares those numbers directly rather than parsing the visible "X min read" text.

Yes — add a new <option> to the select, and a new comparator branch in applySort() reading each card's title text (e.g. via querySelector('.card-title').textContent) for the comparison.

No — each is a CSS gradient keyed off a --h hue variable, so the grid works immediately with no images. Swap in real cover photography by changing .bsblog-cover's background.

Yes — bg-success-subtle and its -emphasis text counterpart are newer Bootstrap 5.3 utility variants specifically designed for lower-contrast label use, versus the older solid bg-success style.