Comment Component
Comment Component: UIKit provides a comprehensive comment system for building threaded discussions, feedback sections, and social comment features. It includes nested comments, user avatars, timestamps, and voting systems.
Live Examples
1. Basic Comment Structure
This is a great article! I found the section about responsive design particularly helpful. Looking forward to more content like this.
Thanks for sharing this information. Could you elaborate more on the grid system examples?
2. Nested Comments (Threaded Replies)
What are your thoughts on using CSS Grid versus Flexbox for complex layouts?
3. Comment with Actions & Voting
This tutorial saved me hours of work! The examples are clear and easy to follow. I especially appreciate the real-world use cases.
Thanks for the feedback everyone! I'm glad you found the tutorial helpful. I'll be creating more advanced tutorials soon.
4. Comment Forms & Reply System
Add a Comment
Has anyone tried implementing this with React? I'm curious about the best approach.
This solution worked perfectly for my project. The performance improvement was significant!
5. Comment List & Pagination
Comment Classes Reference
Core Classes
| Class | Description | Usage |
|---|---|---|
.uk-comment | Base comment container | <article class="uk-comment"> |
.uk-comment-primary | Primary style comment | uk-comment uk-comment-primary |
.uk-comment-default | Default style comment | uk-comment uk-comment-default |
.uk-comment-secondary | Secondary style comment | uk-comment uk-comment-secondary |
.uk-comment-body | Comment content area | <div class="uk-comment-body"> |
.uk-comment-header | Comment header area | <header class="uk-comment-header"> |
.uk-comment-footer | Comment footer area | <footer class="uk-comment-footer"> |
Structure Classes
| Class | Description | Usage |
|---|---|---|
.uk-comment-title | Comment author name/title | <h4 class="uk-comment-title"> |
.uk-comment-meta | Comment metadata (time, actions) | <ul class="uk-comment-meta"> |
.uk-comment-avatar | User avatar/image | <img class="uk-comment-avatar"> |
.uk-comment-list | Container for multiple comments | <div class="uk-comment-list"> |
.uk-comment-reply | Reply form container | <div class="uk-comment-reply"> |
Complete Real-World Examples
Blog Post Comments Section
<!-- Blog Comments Section -->
<div class="uk-card uk-card-default uk-card-body">
<h2 class="uk-card-title">Comments Section</h2>
<!-- Comment Stats -->
<div class="uk-grid-small uk-flex-middle" uk-grid>
<div class="uk-width-expand">
<div class="uk-flex uk-flex-middle">
<div class="uk-margin-small-right">
<span class="uk-text-large uk-text-bold">42</span>
<span class="uk-text-meta">Comments</span>
</div>
<div class="uk-margin-small-right">
<span class="uk-text-large uk-text-bold">128</span>
<span class="uk-text-meta">Replies</span>
</div>
<div>
<span class="uk-label uk-label-success">
<span uk-icon="icon: comments"></span>
Active Discussion
</span>
</div>
</div>
</div>
<div class="uk-width-auto">
<div class="uk-inline">
<button class="uk-button uk-button-default" type="button">
Sort By <span uk-icon="icon: triangle-down"></span>
</button>
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav">
<li class="uk-active"><a href="#">Newest First</a></li>
<li><a href="#">Oldest First</a></li>
<li><a href="#">Most Liked</a></li>
<li><a href="#">Author Replies</a></li>
</ul>
</div>
</div>
</div>
</div>
<!-- Featured Comments -->
<div class="uk-margin-medium-top">
<h3 class="uk-heading-divider">Featured Comments</h3>
<div class="uk-comment-list">
<article class="uk-comment uk-comment-primary uk-card uk-card-secondary uk-card-body">
<header class="uk-comment-header uk-grid-medium uk-flex-middle" uk-grid>
<div class="uk-width-auto">
<img class="uk-comment-avatar uk-border-circle" src="featured-avatar.jpg" width="60" height="60" alt="Featured User">
</div>
<div class="uk-width-expand">
<h4 class="uk-comment-title uk-margin-remove">
<a class="uk-link-reset" href="#">Expert Reviewer</a>
<span class="uk-label uk-label-warning uk-margin-small-left">Expert</span>
</h4>
<div class="uk-comment-meta">
<span>Technical Reviewer • 2 days ago</span>
</div>
</div>
<div class="uk-width-auto">
<button class="uk-button uk-button-default">
<span uk-icon="icon: star"></span>
Featured
</button>
</div>
</header>
<div class="uk-comment-body">
<p>This is an excellent tutorial that covers all the essential aspects of UIKit's comment system. The examples are practical and well-explained.</p>
<div class="uk-alert-success" uk-alert>
<p><strong>Editor's Note:</strong> This comment has been featured for its detailed and helpful feedback.</p>
</div>
</div>
</article>
</div>
</div>
<!-- All Comments -->
<div class="uk-margin-medium-top">
<h3 class="uk-heading-divider">All Comments</h3>
<div class="uk-comment-list">
<!-- Comment threads would go here -->
</div>
</div>
<!-- Comment Form -->
<div class="uk-margin-large-top">
<div class="uk-card uk-card-secondary uk-card-body">
<h3 class="uk-card-title">Join the Discussion</h3>
<form class="uk-grid-small" uk-grid>
<div class="uk-width-1-1">
<textarea class="uk-textarea" rows="5" placeholder="Share your thoughts... (Markdown supported)"></textarea>
</div>
<div class="uk-width-1-2@s">
<div class="uk-text-small">
<label><input class="uk-checkbox" type="checkbox"> Notify me of new comments</label>
</div>
</div>
<div class="uk-width-1-2@s">
<div class="uk-flex uk-flex-right">
<button class="uk-button uk-button-default uk-margin-small-right" type="button">Preview</button>
<button class="uk-button uk-button-primary" type="submit">Post Comment</button>
</div>
</div>
</form>
</div>
</div>
</div>Product Review System
<!-- Product Reviews -->
<div class="uk-card uk-card-default uk-card-body">
<h2 class="uk-card-title">Customer Reviews</h2>
<!-- Review Summary -->
<div class="uk-grid-medium" uk-grid>
<div class="uk-width-1-3@m">
<div class="uk-text-center">
<div class="uk-text-large uk-text-bold">4.5</div>
<div class="uk-margin-small">
<span class="uk-text-warning" uk-icon="icon: star; ratio: 0.8"></span>
<span class="uk-text-warning" uk-icon="icon: star; ratio: 0.8"></span>
<span class="uk-text-warning" uk-icon="icon: star; ratio: 0.8"></span>
<span class="uk-text-warning" uk-icon="icon: star; ratio: 0.8"></span>
<span class="uk-text-warning" uk-icon="icon: star; ratio: 0.8"></span>
</div>
<div class="uk-text-meta">Based on 128 reviews</div>
</div>
</div>
<div class="uk-width-2-3@m">
<!-- Rating breakdown -->
<div class="uk-grid-small uk-child-width-1-1" uk-grid>
<div>
<div class="uk-flex uk-flex-middle">
<div class="uk-width-expand">
<div class="uk-progress">
<div class="uk-progress-bar" style="width: 80%;"></div>
</div>
</div>
<div class="uk-width-auto uk-text-small uk-margin-small-left">
5 stars (102)
</div>
</div>
</div>
<!-- More rating bars... -->
</div>
</div>
</div>
<!-- Reviews List -->
<div class="uk-margin-medium-top">
<div class="uk-comment-list">
<!-- Review 1 -->
<article class="uk-comment uk-comment-default uk-padding uk-background-muted uk-border-rounded">
<header class="uk-comment-header uk-grid-medium uk-flex-middle" uk-grid>
<div class="uk-width-auto">
<img class="uk-comment-avatar uk-border-circle" src="user1.jpg" width="50" height="50" alt="User">
</div>
<div class="uk-width-expand">
<h4 class="uk-comment-title uk-margin-remove">
<a class="uk-link-reset" href="#">Verified Buyer</a>
<span class="uk-label uk-label-success uk-margin-small-left">Verified Purchase</span>
</h4>
<div class="uk-comment-meta">
<div class="uk-flex uk-flex-wrap uk-flex-middle">
<div class="uk-margin-small-right">
<span class="uk-text-warning" uk-icon="icon: star"></span>
<span class="uk-text-warning" uk-icon="icon: star"></span>
<span class="uk-text-warning" uk-icon="icon: star"></span>
<span class="uk-text-warning" uk-icon="icon: star"></span>
<span class="uk-text-warning" uk-icon="icon: star"></span>
</div>
<div>Purchased on December 12, 2023</div>
</div>
</div>
</div>
</header>
<div class="uk-comment-body">
<h5>Excellent product quality!</h5>
<p>The product arrived on time and works exactly as described. The build quality is excellent and it's very easy to use.</p>
<!-- Review Images -->
<div class="uk-grid-small uk-child-width-1-4" uk-grid>
<div>
<img src="review-image1.jpg" alt="Product Image">
</div>
<div>
<img src="review-image2.jpg" alt="Product Image">
</div>
</div>
<!-- Helpful Votes -->
<div class="uk-flex uk-flex-between uk-flex-middle uk-margin-top">
<div>
<span class="uk-text-meta">Was this review helpful?</span>
<button class="uk-button uk-button-text uk-margin-small-left">Yes (24)</button>
<button class="uk-button uk-button-text">No (2)</button>
</div>
<div>
<button class="uk-button uk-button-text">Report</button>
</div>
</div>
</div>
<!-- Seller Response -->
<div class="uk-comment-reply uk-margin-top">
<article class="uk-comment uk-comment-primary">
<header class="uk-comment-header uk-grid-medium uk-flex-middle" uk-grid>
<div class="uk-width-auto">
<span class="uk-icon uk-icon-image" style="background-color: #1e87f0; color: white; padding: 5px; border-radius: 50%;">S</span>
</div>
<div class="uk-width-expand">
<h4 class="uk-comment-title uk-margin-remove">
<span class="uk-text-bold">Seller Response</span>
<span class="uk-label uk-label-warning uk-margin-small-left">Official Response</span>
</h4>
<div class="uk-comment-meta">
<span>December 13, 2023</span>
</div>
</div>
</header>
<div class="uk-comment-body">
<p>Thank you for your positive review! We're glad you're satisfied with our product. If you have any questions, please don't hesitate to contact our support team.</p>
</div>
</article>
</div>
</article>
<!-- More reviews... -->
</div>
</div>
</div>Custom Comment Styles
/* Custom Comment Styles */
/* Chat-style Comments */
.uk-comment-chat {
max-width: 80%;
margin-left: auto;
margin-right: 0;
background: #e3f2fd;
border-radius: 15px 15px 0 15px;
padding: 15px;
}
.uk-comment-chat .uk-comment-header {
margin-bottom: 10px;
}
.uk-comment-chat .uk-comment-body {
padding: 0;
}
/* Timeline Comments */
.uk-comment-timeline {
position: relative;
padding-left: 40px;
}
.uk-comment-timeline:before {
content: '';
position: absolute;
left: 15px;
top: 0;
bottom: 0;
width: 2px;
background: #e5e5e5;
}
.uk-comment-timeline .uk-comment-avatar {
position: absolute;
left: -40px;
top: 0;
border: 3px solid white;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
/* Card-style Comments */
.uk-comment-card {
border: 1px solid #e5e5e5;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
transition: all 0.3s ease;
}
.uk-comment-card:hover {
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
/* Minimal Comments */
.uk-comment-minimal {
background: none;
border: none;
padding: 0;
}
.uk-comment-minimal .uk-comment-header {
margin-bottom: 5px;
}
.uk-comment-minimal .uk-comment-body {
padding: 0;
font-size: 0.9em;
}
/* Gradient Background Comments */
.uk-comment-gradient {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 10px;
padding: 20px;
}
.uk-comment-gradient .uk-comment-title a {
color: white;
}
.uk-comment-gradient .uk-comment-meta {
color: rgba(255,255,255,0.8);
}
/* Comment with Quote */
.uk-comment-quote {
border-left: 4px solid #1e87f0;
padding-left: 20px;
background: #f8f9fa;
}
.uk-comment-quote .uk-comment-body:before {
content: '"';
font-size: 3em;
color: #1e87f0;
line-height: 0;
vertical-align: -0.4em;
}
.uk-comment-quote .uk-comment-body:after {
content: '"';
font-size: 3em;
color: #1e87f0;
line-height: 0;
vertical-align: -0.4em;
}
/* Animated Comments */
.uk-comment-animated {
animation: fadeInUp 0.5s ease;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Comment Badge Styles */
.uk-comment-badge {
position: relative;
}
.uk-comment-badge:after {
content: 'NEW';
position: absolute;
top: -10px;
right: -10px;
background: #f0506e;
color: white;
padding: 3px 8px;
border-radius: 12px;
font-size: 0.7em;
font-weight: bold;
}
/* Usage Examples */
<article class="uk-comment uk-comment-chat">
<!-- Chat style comment -->
</article>
<article class="uk-comment uk-comment-timeline">
<!-- Timeline comment -->
</article>
<article class="uk-comment uk-comment-card">
<!-- Card style comment -->
</article>
<article class="uk-comment uk-comment-gradient">
<!-- Gradient comment -->
</article>
<article class="uk-comment uk-comment-quote">
<!-- Quote style comment -->
</article>
<article class="uk-comment uk-comment-animated">
<!-- Animated comment -->
</article>Best Practices for Comment Systems:
- Always include user avatars for better visual identification
- Use clear timestamps and relative time formats
- Implement nested comments with proper indentation levels
- Provide moderation tools for administrators
- Include voting/rating systems for community moderation
- Implement spam protection and content filtering
- Make comment forms accessible and user-friendly
- Support markdown or rich text formatting
- Include notification systems for replies
- Implement pagination for large comment threads
- Ensure mobile-responsive comment layouts
- Provide keyboard navigation for accessibility
- Include user verification badges for trusted users
- Implement comment sorting options (newest, oldest, top-rated)
- Add report/flag functionality for inappropriate content
Sarah Miller
I prefer CSS Grid for two-dimensional layouts and Flexbox for one-dimensional layouts. They work great together!
Mike Chen
I agree with Sarah. CSS Grid is perfect for overall page layout, while Flexbox is great for components.
David Wilson
Don't forget about browser support. CSS Grid has excellent support now, but Flexbox is still more widely supported.