Word Counter Tool body { font-family: Arial, sans-serif; margin: 20px; padding: 0; background-color: #f4f4f4; } h1 { text-align: center; } #wordCount, #charCount { font-size: 18px; margin-top: 10px; } textarea { width: 100%; height: 200px; padding: 10px; font-size: 16px; margin-top: 20px; border: 1px solid #ccc; border-radius: 5px; resize: none; } .counter { text-align: center; margin-top: 10px; } Word Counter Tool Enter your text below to count the words and characters: Words: 0 Characters: 0 const textInput = document.getElementById('textInput'); const wordCount = document.getElementById('wordCount'); const charCount = document.getElementById('charCount'); // Function to update word and character count function updateCounts() { const text = textInput.value.trim(); const words = text.split(/\s+/).filter(word => word.length > 0); const characters = text.replace(/\s/g, '').length; wordCount.textContent = `Words: ${words.length}`; charCount.textContent = `Characters: ${characters}`; } // Event listener for input change textInput.addEventListener('input', updateCounts);