webdevpuneet.com

Bootstrap Profile Card with Follow Toggle — Free Snippet

Bootstrap Profile Card with Follow Toggle · Cards · Plain HTML, CSS & JS · Live preview

CategoryCards

Copy & paste

Source Code

<div class="container py-5 d-flex justify-content-center">
  <div class="card bsprofile-card">
    <div class="bsprofile-cover"></div>
    <div class="card-body text-center">
      <div class="bsprofile-avatar mx-auto">DR</div>
      <h5 class="card-title mb-0">Dana Reyes</h5>
      <p class="text-muted small mb-3">Head of Product · Fenwick</p>
      <div class="d-flex justify-content-center gap-4 mb-3">
        <div><strong id="bsprofileFollowers">2,481</strong><div class="text-muted small">Followers</div></div>
        <div><strong>312</strong><div class="text-muted small">Following</div></div>
        <div><strong>48</strong><div class="text-muted small">Posts</div></div>
      </div>
      <button class="btn w-100 fw-bold bsprofile-follow" id="bsprofileBtn" data-following="false">Follow</button>
    </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 component with an overlapping avatar and cover banner
Genuinely toggling Follow/Following state via a data attribute, not just static styling
Follower count increments and decrements exactly in sync with the toggle
Hover-to-reveal "(Unfollow)" preview on an already-followed button, a common social-app pattern
Distinct visual styles for followed vs. not-followed states
Self-contained — no external avatar image required to try it

About this UI Snippet

Bootstrap Profile Card with Follow Toggle — HTML, CSS & JavaScript

Screenshot of the Bootstrap Profile Card with Follow Toggle snippet rendered live

A profile card's Follow button is usually the only interactive element on the card, and this snippet makes sure it's genuinely functional: clicking it toggles a data-following attribute between "false" and "true", swaps the button's own text between "Follow" and "Following", and adjusts the visible follower count by exactly one — an increment when you follow, back down when you unfollow — built on real Bootstrap 5.3's .card component.

The hover state on an already-followed button is a deliberate, common social-app pattern: hovering "Following" reveals "(Unfollow)" and a red-tinted style, previewing what the click will do before it happens, so unfollowing never feels accidental.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads a profile card with "Follow" and 2,481 followers.
  2. 2
    Click FollowThe button becomes "Following" (light style) and the follower count increments to 2,482.
  3. 3
    Hover the Following buttonIt shows "(Unfollow)" in a red-tinted style, previewing what clicking again will do.
  4. 4
    Click again to unfollowThe button reverts to "Follow" and the count drops back to 2,481.

Real-world uses

Common Use Cases

Social and community platform profile cards
The standard follow-toggle pattern used across social products, built here on real Bootstrap markup.
Learning data-attribute-driven toggle state
A clean example of using a data attribute (rather than a class alone) to track and style a two-state toggle.
Team directories and community member lists
Reuse the card shape for a team or community directory, following/unfollowing colleagues or members.
Any card needing a genuine two-state action button
The hover-reveal pattern generalizes to any "undo-able" toggle action beyond following — saving, subscribing, bookmarking.

Got questions?

Frequently Asked Questions

It updates the displayed number in this front-end demo, incrementing or decrementing by one to reflect your own follow action. Wire the click handler to a real API call for actual persistence.

A data-following attribute on the button itself holds "true" or "false", read and flipped on each click — CSS attribute selectors ([data-following="true"]) drive the different visual styles for each state.

It's a deliberate UX pattern: previewing the consequence of a click before it happens (via CSS ::after content and a color change) makes an unfollow action feel intentional rather than an accidental double-click.

Yes — replace .bsprofile-avatar's content and background with an <img> tag; keep the same circular sizing and negative top margin so it still overlaps the cover banner correctly.

The button's visible text already changes between "Follow" and "Following" (not just its color), so its state is conveyed to screen readers through the same text content a sighted user reads.