What separates a usable comment thread from a merely functional one
A comment thread looks trivial when it's done well, which is exactly why it's easy to underestimate while building one. The design goals that matter most:
- Readability. Author, vote count, timestamp, and content should all be legible at a glance.
- Visual separation. The parts of a comment must be distinguishable, particularly action buttons like reply and report, and any links.
- Hierarchy cues. Nested comments, where one comment replies to another, need visible indicators of depth.
- Fast navigation. Users should be able to jump quickly to a comment — above all from a reply to its parent.
- Toggling. A comment and its replies should be hideable and showable on demand.
Other enhancements exist — flagging for moderators, up/down voting, loading only the first few comments — but they require at least some JavaScript, or can live entirely server-side depending on the stack. The focus here is purely on styling, since that alone can cover the five points above.
Building the markup and the hierarchy cue
A single comment has a simple skeleton. Replies carry extra left margin, which supplies the hierarchy cue described in point 3:

The corresponding markup is nothing more than nested containers holding basic elements:
<div class="comment">
<!-- Comment heading start -->
<div class="comment-heading">
<!-- Comment voting start -->
<div class="comment-voting">
<button type="button">Vote up</button>
<button type="button">Vote down</button>
</div>
<!-- Comment voting end -->
<!-- Comment info (author, # of votes, time added) start -->
<div class="comment-info">
<a href="#" class="comment-author">{{ author }}</a>
<p>
{{ # of votes }} • {{ time_added }}
</p>
</div>
<!-- Comment info (author, # of votes, time added) end -->
</div>
<!-- Comment heading end -->
<!-- Comment body start -->
<div class="comment-body">
<p>
{{ comment_content }}
</p>
<button type="button">Reply</button>
<button type="button">Flag</button>
</div>
<!-- Comment body end -->
<!-- Replies start -->
<div class="replies">
<!-- ... -->
</div>
<!-- Replies end -->
</div>
In a fleshed-out example with a reply, three implementation details stand out:
- Left margin on replies provides the visual cue for nesting.
- The vote up and vote down buttons use HTML character codes for their icons.
- The
.sr-onlyclass hides elements from view on all devices except screen readers, which keeps the voting buttons accessible. Frameworks like Bootstrap or Halfmoon ship this class already.
Clickable border links for jumping between comments
To move quickly between a reply and its parent, a clickable border on the left side of the comment works well. Adding it means pushing the comment body to the right so it aligns with the replies, and the result doubles as a stronger hierarchy signal: count the border links on the left and you know the nesting level of the comment you're reading. Clicking any of them jumps you to that level.

Mechanically, anchor elements (<a href="...">) go inside each comment and are styled to look like left-hand borders. The key points:
- The
.comment-heading, holding votes, author, and timestamp, has a fixedheightof50px. Withposition: absolute,top: 50px, andheight: calc(100% - 50px), the border links start right below the heading and run to the bottom of the comment. - The border links have a clipped background and a
widthof12pxwith aborder-widthof4pxon the left and right. Only4pxis visible, but the whole12pxis clickable —4pxalone is too narrow a target, while anything wider would look wrong.
Toggling visibility without JavaScript
The path of least resistance for hide/show behavior is the native <details> and <summary> elements: clicking the <summary> toggles the <details>. No JavaScript is needed, and browser support sits at roughly 96%. Three changes implement it:
- Turn every
.commentelement from a<div>into a<details>element. - Wrap
.comment-headinginside a<summary>tag and remove the default arrow. - Add a visual cue showing whether a comment is hidden.
The details that make it work:
- All comments get the
openattribute so they start visible. - The visibility cue is small text on the right, generated as a pseudo-element with
::after, whose content depends on whether the parent<details>has theopenattribute. Collapsed comments also gain a bottom border to signal there is more content. - At the end of the CSS, an
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {...}selector targets Internet Explorer only. IE doesn't support<details>, so comments are always open there; removing the cue text and resetting the cursor leaves IE users with a normal, non-toggleable thread — no harm done.
Edge cases worth designing for
The empty state
It's easy to overlook. When there are no comments, say so: a paragraph reading "There are no comments yet." next to a form with a text box and submit button is the bare minimum. A relevant image alongside the form is a reasonable extra step.
Reply forms
Implementations vary. Some sites redirect to a separate page with a text box and submit button; others toggle a form open inside the thread itself. The in-thread approach needs JavaScript but is dominant today. In practice, forms live inside comment bodies with a .d-none class (i.e. display: none;) by default, and a simple event listener lets any button carrying data-toggle="reply-form" and data-target="{{ comment_reply_form_id }}" toggle the matching form.
Placement of a just-posted reply
After a user submits a reply, show it above the existing replies. Someone who fills out a form wants immediate confirmation, and placing the new reply first delivers that without requiring a scroll. On later page loads, sort replies by whatever algorithm suits the site.
Markdown and code blocks
Developer-oriented sites often need this, but it's a topic big enough for its own article. A Markdown editor can generally be attached to a text box fairly easily; most are JavaScript-based and fit the examples here. One option is markdown-it, under a permissive MIT license. WYSIWYG editors serve a similar purpose.
Spam and authentication
Any input form invites spam. A service such as Google's reCAPTCHA reduces it — a reCAPTCHA box could sit right below the Submit button in a reply form. Requiring authentication is the other lever: every comment links to an account, which gives moderators a way to deal with repeat spammers. In the UI, clicking Reply or Post comment while logged out can redirect to a login page, then return the user to the thread with the form opened.
All five design goals are met by the above, and the bulk of the thread works in CSS alone — no JavaScript — which says something about how far CSS has come.



