The user wants me to create a live character-counting tool for text areas with real-time feedback. This should include:
- HTML - Text area(s) with character count displays
- CSS - Styling for the interface and visual feedback
- JS - Real-time character counting functionality
Let me create a comprehensive, feature-rich implementation that includes:
- Multiple text areas with different configurations
- Character limit settings
- Visual feedback (colors changing as limit approaches)
- Word count as well
- Progress bar visualization
- Warning states
- Maybe copy/clear functionality
- Responsive design
- Accessibility considerations
Let me build this out:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Character Counter</title>
<style>
/* CSS here */
</style>
</head>
<body>
<!-- HTML here -->
<script>
// JS here
</script>
</body>
</html>
Let me create a complete implementation with:
- A clean, modern UI
- Multiple text area examples (tweet-like, bio, article)
- Real-time character and word counting
- Progress bars
- Color-coded feedback
- Copy and clear buttons
- Mobile responsive # Live Character Counter Tool
Here's a comprehensive character-counting tool with real-time feedback:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Character Counter</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
padding: 20px;
color: #fff;
}
.container {
max-width: 900px;
margin: 0 auto;
}
header {
text-align: center;
margin-bottom: 40px;
}
header h1 {
font-size: 2.5rem;
background: linear-gradient(90deg, #00d9ff, #00ff88);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 10px;
}
header p {
color: #8892b0;
font-size: 1.1rem;
}
.text-area-container {
background: rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 24px;
margin-bottom: 24px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
}
.text-area-container:hover {
border-color: rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.text-area-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.text-area-title {
display: flex;
align-items: center;
gap: 10px;
}
.text-area-title h3 {
font-size: 1.2rem;
color: #fff;
}
.text-area-title .icon {
font-size: 1.4rem;
}
.limit-badge {
background: rgba(0, 217, 255, 0.2);
color: #00d9ff;
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
}
.textarea-wrapper {
position: relative;
}
textarea {
width: 100%;
min-height: 150px;
padding: 16px;
background: rgba(0, 0, 0, 0.3);
border: 2px solid rgba(255, 255, 255, 0.1);
border-radius: 12px;
color: #fff;
font-size: 1rem;
font-family: inherit;
line-height: 1.6;
resize: vertical;
transition: all 0.3s ease;
}
textarea:focus {
outline: none;
border-color: #00d9ff;
box-shadow: 0 0 0 4px rgba(0, 217, 255, 0.1);
}
textarea::placeholder {
color: #5a6a8a;
}
textarea.warning {
border-color: #ffa500;
box-shadow: 0 0 0 4px rgba(255, 165, 0, 0.1);
}
textarea.danger {
border-color: #ff4757;
box-shadow: 0 0 0 4px rgba(255, 71, 87, 0.1);
}
textarea.over-limit {
border-color: #ff0044;
background: rgba(255, 0, 68, 0.1);
}
/* Progress Bar */
.progress-container {
margin-top: 16px;
}
.progress-bar {
height: 6px;
background: rgba(255, 255, 255, 0.1);
border-radius: 3px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #00d9ff, #00ff88);
border-radius: 3px;
transition: all 0.3s ease;
width: 0%;
}
.progress-fill.warning {
background: linear-gradient(90deg, #ffa500, #ff8c00);
}
.progress-fill.danger {
background: linear-gradient(90deg, #ff4757, #ff0044);
}
.progress-fill.over-limit {
background: #ff0044;
}
/* Stats Row */
.stats-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 16px;
flex-wrap: wrap;
gap: 12px;
}
.stats {
display: flex;
gap: 20px;
}
.stat-item {
display: flex;
align-items: center;
gap: 6px;
font-size: 0.9rem;
color: #8892b0;
}
.stat-item .value {
color: #00d9ff;
font-weight: 600;
}
.stat-item.warning .value {
color: #ffa500;
}
.stat-item.danger .value {
color: #ff4757;
}
.stat-item.over-limit .value {
color: #ff0044;
}
/* Character Count Display */
.char-count {
font-size: 1.1rem;
font-weight: 600;
transition: all 0.3s ease;
}
.char-count .current {
color: #00ff88;
}
.char-count.warning .current {
color: #ffa500;
}
.char-count.danger .current {
color: #ff4757;
}
.char-count.over-limit .current {
color: #ff0044;
}
.char-count .separator {
color: #5a6a8a;
margin: 0 4px;
}
.char-count .max {
color: #5a6a8a;
}
.remaining {
font-size: 0.85rem;
color: #5a6a8a;
margin-left: 8px;
}
.remaining.warning {
color: #ffa500;
}
.remaining.danger {
color: #ff4757;
animation: pulse 1s infinite;
}
.remaining.over-limit {
color: #ff0044;
font-weight: 600;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* Action Buttons */
.actions {
display: flex;
gap: 8px;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 0.85rem;
font-weight: 600;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 6px;
}
.btn-copy {
background: rgba(0, 217, 255, 0.2);
color: #00d9ff;
}
.btn-copy:hover {
background: rgba(0, 217, 255, 0.3);
transform: translateY(-2px);
}
.btn-clear {
background: rgba(255, 71, 87, 0.2);
color: #ff4757;
}
.btn-clear:hover {
background: rgba(255, 71, 87, 0.3);
transform: translateY(-2px);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
/* Circular Progress (Alternative Display) */
.circular-container {
display: flex;
gap: 30px;
align-items: flex-start;
}
.circular-progress-wrapper {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
min-width: 100px;
}
.circular-progress {
position: relative;
width: 80px;
height: 80px;
}
.circular-progress svg {
transform: rotate(-90deg);
}
.circular-progress circle {
fill: none;
stroke-width: 6;
}
.circular-progress .bg {
stroke: rgba(255, 255, 255, 0.1);
}
.circular-progress .progress {
stroke: #00d9ff;
stroke-linecap: round;
transition: all 0.3s ease;
stroke-dasharray: 226;
stroke-dashoffset: 226;
}
.circular-progress .progress.warning {
stroke: #ffa500;
}
.circular-progress .progress.danger {
stroke: #ff4757;
}
.circular-progress .progress.over-limit {
stroke: #ff0044;
}
.circular-progress .percentage {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 1rem;
font-weight: 700;
color: #fff;
}
.circular-label {
font-size: 0.8rem;
color: #8892b0;
text-align: center;
}
.flex-grow {
flex: 1;
}
/* Toast Notification */
.toast {
position: fixed;
bottom: 30px;
right: 30px;
background: #00ff88;
color: #000;
padding: 14px 24px;
border-radius: 10px;
font-weight: 600;
box-shadow: 0 4px 20px rgba(0, 255, 136, 0.4);
transform: translateY(100px);
opacity: 0;
transition: all 0.3s ease;
z-index: 1000;
}
.toast.show {
transform: translateY(0);
opacity: 1;
}
/* Live Preview Section */
.preview-section {
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.preview-label {
font-size: 0.85rem;
color: #5a6a8a;
margin-bottom: 8px;
}
.preview-content {
background: rgba(0, 0, 0, 0.3);
padding: 16px;
border-radius: 8px;
color: #8892b0;
min-height: 60px;
word-wrap: break-word;
line-height: 1.6;
}
.preview-content .highlighted {
background: rgba(255, 71, 87, 0.3);
color: #ff4757;
border-radius: 2px;
}
/* Responsive */
@media (max-width: 768px) {
header h1 {
font-size: 1.8rem;
}
.text-area-container {
padding: 16px;
}
.text-area-header {
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
.stats-row {
flex-direction: column;
align-items: flex-start;
}
.circular-container {
flex-direction: column;
}
.stats {
flex-wrap: wrap;
}
}
/* Themes */
.theme-selector {
display: flex;
justify-content: center;
gap: 12px;
margin-bottom: 30px;
}
.theme-btn {
width: 30px;
height: 30px;
border-radius: 50%;
border: 2px solid transparent;
cursor: pointer;
transition: all 0.3s ease;
}
.theme-btn:hover {
transform: scale(1.1);
}
.theme-btn.active {
border-color: #fff;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
.theme-btn.dark { background: #1a1a2e; }
.theme-btn.blue { background: #0066ff; }
.theme-btn.purple { background: #6c5ce7; }
.theme-btn.green { background: #00b894; }
</style>
</head>
<body>
<div class="container">
<header>
<h1>📝 Live Character Counter</h1>
<p>Real-time feedback for your text with visual indicators</p>
</header>
<div class="theme-selector">
<button class="theme-btn dark active" data-theme="dark" title="Dark Theme"></button>
<button class="theme-btn blue" data-theme="blue" title="Blue Theme"></button>
<button class="theme-btn purple" data-theme="purple" title="Purple Theme"></button>
<button class="theme-btn green" data-theme="green" title="Green Theme"></button>
</div>
<!-- Twitter-style (280 chars) -->
<div class="text-area-container" data-limit="280">
<div class="text-area-header">
<div class="text-area-title">
<span class="icon">🐦</span>
<h3>Tweet</h3>
</div>
<span class="limit-badge">280 characters</span>
</div>
<div class="textarea-wrapper">
<textarea
class="char-textarea"
placeholder="What's happening? Write your tweet here..."
data-max="280"
></textarea>
</div>
<div class="progress-container">
<div class="progress-bar">
<div class="progress-fill"></div>
</div>
</div>
<div class="stats-row">
<div class="stats">
<div class="stat-item char-stat">
<span>Characters:</span>
<span class="value char-value">0</span>
</div>
<div class="stat-item">
<span>Words:</span>
<span class="value word-value">0</span>
</div>
<div class="stat-item">
<span>Lines:</span>
<span class="value line-value">0</span>
</div>
</div>
<div style="display: flex; align-items: center;">
<div class="char-count">
<span class="current">0</span>
<span class="separator">/</span>
<span class="max">280</span>
</div>
<span class="remaining">(280 remaining)</span>
</div>
</div>
<div class="stats-row">
<div class="actions">
<button class="btn btn-copy" disabled>
<span>📋</span> Copy
</button>
<button class="btn btn-clear" disabled>
<span>🗑️</span> Clear
</button>
</div>
</div>
</div>
<!-- Bio-style (160 chars) with Circular Progress -->
<div class="text-area-container" data-limit="160">
<div class="text-area-header">
<div class="text-area-title">
<span class="icon">👤</span>
<h3>Profile Bio</h3>
</div>
<span class="limit-badge">160 characters</span>
</div>
<div class="circular-container">
<div class="textarea-wrapper flex-grow">
<textarea
class="char-textarea"
placeholder="Write a short bio about yourself..."
data-max="160"
style="min-height: 100px;"
></textarea>
</div>
<div class="circular-progress-wrapper">
<div class="circular-progress">
<svg width="80" height="80">
<circle class="bg" cx="40" cy="40" r="36"></circle>
<circle class="progress" cx="40" cy="40" r="36"></circle>
</svg>
<span class="percentage">0%</span>
</div>
<span class="circular-label">Character Usage</span>
</div>
</div>
<div class="stats-row">
<div class="stats">
<div class="stat-item char-stat">
<span>Characters:</span>
<span class="value char-value">0</span>
</div>
<div class="stat-item">
<span>Words:</span>
<span class="value word-value">0</span>
</div>
</div>
<div class="actions">
<button class="btn btn-copy" disabled>
<span>📋</span> Copy
</button>
<button class="btn btn-clear" disabled>
<span>🗑️</span> Clear
</button>
</div>
</div>
</div>
<!-- Article/Blog style (5000 chars) with Preview -->
<div class="text-area-container" data-limit="5000">
<div class="text-area-header">
<div class="text-area-title">
<span class="icon">📄</span>
<h3>Article / Blog Post</h3>
</div>
<span class="limit-badge">5000 characters</span>
</div>
<div class="textarea-wrapper">
<textarea
class="char-textarea"
placeholder="Start writing your article here. You have plenty of space to express your ideas..."
data-max="5000"
style="min-height: 200px;"
></textarea>
</div>
<div class="progress-container">
<div class="progress-bar">
<div class="progress-fill"></div>
</div>
</div>
<div class="stats-row">
<div class="stats">
<div class="stat-item char-stat">
<span>Characters:</span>
<span class="value char-value">0</span>
</div>
<div class="stat-item">
<span>Words:</span>
<span class="value word-value">0</span>
</div>
<div class="stat-item">
<span>Sentences:</span>
<span class="value sentence-value">0</span>
</div>
<div class="stat-item">
<span>Paragraphs:</span>
<span class="value para-value">0</span>
</div>
<div class="stat-item">
<span>Read time:</span>
<span class="value read-time">0 min</span>
</div>
</div>
<div style="display: flex; align-items: center;">
<div class="char-count">
<span class="current">0</span>
<span class="separator">/</span>
<span class="max">5000</span>
</div>
<span class="remaining">(5000 remaining)</span>
</div>
</div>
<div class="stats-row">
<div class="actions">
<button class="btn btn-copy" disabled>
<span>📋</span> Copy
</button>
<button class="btn btn-clear" disabled>
<span>🗑️</span> Clear
</button>
</div>
</div>
<div class="preview-section">
<div class="preview-label">📖 Live Preview (excess characters highlighted)</div>
<div class="preview-content">
<em style="color: #5a6a8a;">Your text will appear here...</em>
</div>
</div>
</div>
</div>
<div class="toast" id="toast">Text copied to clipboard!</div>
<script>
// Theme colors
const themes = {
dark: { primary: '#1a1a2e', secondary: '#16213e' },
blue: { primary: '#0a1628', secondary: '#0d2137' },
purple: { primary: '#1a0a2e', secondary: '#2d1b49' },
green: { primary: '#0a1a14', secondary: '#0d2b1f' }
};
// Theme selector functionality
document.querySelectorAll('.theme-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.theme-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const theme = themes[btn.dataset.theme];
document.body.style.background = `linear-gradient(135deg, ${theme.primary} 0%, ${theme.secondary} 100%)`;
});
});
// Initialize all text areas
document.querySelectorAll('.text-area-container').forEach(container => {
const textarea = container.querySelector('.char-textarea');
const maxChars = parseInt(textarea.dataset.max);
const progressFill = container.querySelector('.progress-fill');
const charCount = container.querySelector('.char-count');
const currentSpan = container.querySelector('.current');
const remaining = container.querySelector('.remaining');
const charValue = container.querySelector('.char-value');
const wordValue = container.querySelector('.word-value');
const lineValue = container.querySelector('.line-value');
const sentenceValue = container.querySelector('.sentence-value');
const paraValue = container.querySelector('.para-value');
const readTime = container.querySelector('.read-time');
const charStat = container.querySelector('.char-stat');
const copyBtn = container.querySelector('.btn-copy');
const clearBtn = container.querySelector('.btn-clear');
const circularProgress = container.querySelector('.circular-progress .progress');
const percentage = container.querySelector('.percentage');
const previewContent = container.querySelector('.preview-content');
// Update counter function
function updateCounter() {
const text = textarea.value;
const charLength = text.length;
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
const lines = text ? text.split('\n').length : 0;
const sentences = text.split(/[.!?]+/).filter(s => s.trim()).length;
const paragraphs = text.split(/\n\n+/).filter(p => p.trim()).length;
const avgReadingSpeed = 200; // words per minute
const readingTime = Math.ceil(words / avgReadingSpeed);
// Calculate percentage
const percent = (charLength / maxChars) * 100;
const remainingChars = maxChars - charLength;
// Determine status
let status = 'normal';
if (percent >= 100) status = 'over-limit';
else if (percent >= 90) status = 'danger';
else if (percent >= 75) status = 'warning';
// Update textarea styling
textarea.classList.remove('warning', 'danger', 'over-limit');
if (status !== 'normal') textarea.classList.add(status);
// Update progress bar
if (progressFill) {
progressFill.style.width = `${Math.min(percent, 100)}%`;
progressFill.classList.remove('warning', 'danger', 'over-limit');
if (status !== 'normal') progressFill.classList.add(status);
}
// Update circular progress
if (circularProgress) {
const circumference = 2 * Math.PI * 36; // radius = 36
const offset = circumference - (Math.min(percent, 100) / 100) * circumference;
circularProgress.style.strokeDashoffset = offset;
circularProgress.classList.remove('warning', 'danger', 'over-limit');
if (status !== 'normal') circularProgress.classList.add(status);
percentage.textContent = `${Math.round(percent)}%`;
}
// Update character count
if (currentSpan) {
currentSpan.textContent = charLength;
}
if (charCount) {
charCount.classList.remove('warning', 'danger', 'over-limit');
if (status !== 'normal') charCount.classList.add(status);
}
// Update remaining
if (remaining) {
if (remainingChars >= 0) {
remaining.textContent = `(${remainingChars} remaining)`;
} else {
remaining.textContent = `(${Math.abs(remainingChars)} over limit!)`;
}
remaining.classList.remove('warning', 'danger', 'over-limit');
if (status !== 'normal') remaining.classList.add(status);
}
// Update stats
if (charValue) charValue.textContent = charLength;
if (wordValue) wordValue.textContent = words;
if (lineValue) lineValue.textContent = lines;
if (sentenceValue) sentenceValue.textContent = sentences;
if (paraValue) paraValue.textContent = paragraphs;
if (readTime) readTime.textContent = `${readingTime} min`;
if (charStat) {
charStat.classList.remove('warning', 'danger', 'over-limit');
if (status !== 'normal') charStat.classList.add(status);
}
// Update buttons
if (copyBtn) copyBtn.disabled = charLength === 0;
if (clearBtn) clearBtn.disabled = charLength === 0;
// Update preview
if (previewContent) {
if (text.trim()) {
if (charLength > maxChars) {
const validText = text.substring(0, maxChars);
const excessText = text.substring(maxChars);
previewContent.innerHTML =
escapeHtml(validText) +
`<span class="highlighted">${escapeHtml(excessText)}</span>`;
} else {
previewContent.innerHTML = escapeHtml(text).replace(/\n/g, '<br>');
}
} else {
previewContent.innerHTML = '<em style="color: #5a6a8a;">Your text will appear here...</em>';
}
}
}
// Escape HTML for preview
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Event listeners
textarea.addEventListener('input', updateCounter);
textarea.addEventListener('paste', () => setTimeout(updateCounter, 0));
// Copy button
if (copyBtn) {
copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(textarea.value);
showToast('Text copied to clipboard!');
} catch (err) {
// Fallback for older browsers
textarea.select();
document.execCommand('copy');
showToast('Text copied to clipboard!');
}
});
}
// Clear button
if (clearBtn) {
clearBtn.addEventListener('click', () => {
textarea.value = '';
updateCounter();
textarea.focus();
});
}
// Initial update
updateCounter();
});
// Toast notification
function showToast(message) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 2000);
}
// Keyboard shortcut hints
document.querySelectorAll('.char-textarea').forEach(textarea => {
// Save with Ctrl/Cmd + S (just prevents default)
textarea.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault();
showToast('Content auto-saved locally!');
}
});
});
</script>
</body>
</html>
Features Included
📊 Real-time Statistics
| Feature | Description |
|---|
| Characters | Live character count |
| Words | Automatic word counting |
| Lines | Number of lines |
| Sentences | Sentence detection |
| Paragraphs | Paragraph counting |
| Read Time | Estimated reading time |
🎨 Visual Feedback
- Progress bars - Linear and circular options
- Color-coded states:
- 🟢 Normal (0-74%)
- 🟡 Warning (75-89%)
- 🔴 Danger (90-99%)
- ⛔ Over limit (100%+)
🛠️ Functionality
- Copy to clipboard button
- Clear text button
- Live preview with excess highlighting
- Theme selector (4 color themes)
- Keyboard shortcuts (Ctrl+S)
📱 Responsive Design
- Mobile-friendly layout
- Touch-optimized controls
- Adaptive statistics display
🎯 Three Example Use Cases
- Tweet (280 chars) - Twitter-style
- Bio (160 chars) - With circular progress
- Article (5000 chars) - Full-featured with preview
To use this, simply save the code as an HTML file and open it in any modern browser!