StealThis .dev

Comment Thread

Nested comment thread with replies, likes, collapse/expand, relative timestamps, and inline reply form. No dependencies.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

Comment Thread

A fully interactive nested comment thread supporting inline reply forms, like/heart toggling, collapse/expand branches, relative timestamps, and new comment posting.

Features

  • Top-level comment form with avatar and textarea
  • Up to 2 levels of nested replies (comment → reply)
  • Inline replied-to indicator showing parent author
  • Like button with animated heart toggle and count increment
  • Collapse thread toggle to hide/show a comment’s replies
  • Relative timestamps (“2 minutes ago”, “Yesterday”, etc.)
  • New comment and new reply appended to the DOM instantly
  • Character count on textarea with soft limit warning

How it works

  1. Comments are rendered from a JS data array on load; renderComment() creates DOM nodes recursively
  2. “Reply” button inserts an inline <form> below the comment; submit appends to that comment’s replies
  3. Likes use a data-liked attribute toggle + CSS class for the filled heart state
  4. timeAgo(date) utility converts Date objects to human-readable relative strings