Skip to content

Comments with Likes and User Photos

Dark Bootstrap 5 comment section with user photos, timestamps, like buttons, inline reply forms, nested replies and Top/Newest sorting.

Also known as: comment section with replies, blog comments thread, nested comments, comment box with likes

Bootstrap 5 Comments Responsive Dark #avatar #comments #dark #likes #replies

Comments with Likes and User Photos live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A dark Bootstrap 5 comment section with round user photos, relative timestamps, heart like buttons with counters, inline reply forms and one level of nested replies. It fits blog posts, documentation pages, changelogs and community feeds where readers should react without leaving the page.

How it works

The root section.cl-comments holds a header with the title, a .cl-count badge and a .cl-sort button group, then the .cl-composer form and an ordered .cl-list. Every comment is an li.cl-item with data-likes and data-time attributes and an article.cl-comment that contains the .cl-avatar photo, a .cl-meta row (name, optional .cl-badge, <time>), the .cl-text paragraph and .cl-actions. Top-level comments also carry a hidden .cl-reply-form and a .cl-replies list, which gets a left border only when it is not empty.

The script initialises every .cl-comments on DOMContentLoaded and uses delegated click, submit and input listeners on the root, so comments added later work without extra wiring. A .cl-like click flips aria-pressed, swaps bi-heart and bi-heart-fill, updates data-likes and the .cl-like__count. A .cl-reply-toggle shows the form named in its aria-controls and focuses the textarea; Cancel hides it and returns focus. Submitting the composer or a reply builds a new comment with DOM methods and textContent, using the name and photo from data-cl-user and data-cl-avatar. The sort buttons reorder top-level items by data-likes or data-time.

The photos come from Unsplash; replace them with your users' own profile images.

Customization

  • --cl-accent in .cl-comments: changes the Post button, active sort button, count badge and focus rings.
  • --cl-like in .cl-comments: sets the color of liked hearts and of empty-field errors.
  • --cl-avatar in .cl-comments: resizes all profile photos; replies use 80% of this size through .cl-avatar--sm.
  • data-cl-user and data-cl-avatar on .cl-comments: the signed-in user's name and photo used for new comments.
  • max-width: 46rem in .cl-comments .cl-wrap: makes the thread wider or narrower.
  • aria-pressed="true" on a [data-cl-sort] button: chooses the sort mode that looks active on load.
  • The composer submit handler in script.js: replace the comment marked with a fetch() call to store comments on your server.

Use cases

  • Blog posts: readers add comments, like others and reply inline without leaving the article
  • Documentation pages: a dark comment thread lets users discuss a page and sort by top or newest
  • Changelogs: people react with heart likes and see relative timestamps on each entry
  • Community feeds: one level of nested replies keeps conversations tidy next to user photos

Accessibility

The sort buttons sit in a labelled role="group" and use aria-pressed. Like buttons carry an aria-label naming the author and expose their state with aria-pressed. Reply toggles use aria-expanded and aria-controls, and every textarea has a visually hidden label. Empty submissions mark the field with is-invalid and move focus to it. A .cl-status live region announces posted comments, replies and sort changes. Focus is shown with a teal outline, text colors keep strong contrast on the dark surface, and the heart pop and slide-in animations stop under prefers-reduced-motion.

Usage notes

Requires Bootstrap 5 (added automatically) and Bootstrap Icons. Several comment sections can live on one page; reply form IDs created by the script are unique.

Comments with Likes and User Photos at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile, dark design
Category
Comments
License
Free for personal and commercial use

Questions about this template

Can I use the Comments with Likes and User Photos code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Comments with Likes and User Photos – Bootstrap 5 comments component screenshot
Comments with Likes and User Photos · Bootstrap 5 Comments

More Comments

Comment Section with Reply Form – Bootstrap 5 comments preview

Comment Section with Reply Form

Bootstrap 5 comment section with threaded replies, collapsible reply forms, like buttons, a new comment form and live comment count.

Comment Thread – Tailwind CSS comments preview

Comment Thread

Nested Tailwind CSS comment thread with threaded replies, like toggles, inline reply forms and a new comment form, built with accessible vanilla JavaScript.