Pages

Thursday, 19 December 2024

Word & Character Counter



Word & Character Counter

Word & Character Counter Tool

Words: 0
Characters: 0
Spaces: 0
body { background: linear-gradient(to right, #4facfe, #00f2fe); font-family: Arial, sans-serif; color: #333; } .text-gradient { background: linear-gradient(to right, #ff416c, #ff4b2b); -webkit-background-clip: text; -webkit-text-fill-color: transparent; } .card { border: none; border-radius: 15px; background: white; } textarea { resize: none; border-radius: 10px; border: 1px solid #ccc; padding: 15px; font-size: 1.2rem; } textarea:focus { outline: none; border-color: #4facfe; box-shadow: 0 0 5px #4facfe; } function updateCounts() { const text = document.getElementById("textInput").value; const wordCount = text.trim().split(/\s+/).filter(Boolean).length; const charCount = text.length; const spaceCount = (text.match(/\s/g) || []).length; document.getElementById("wordCount").innerText = wordCount; document.getElementById("charCount").innerText = charCount; document.getElementById("spaceCount").innerText = spaceCount; } function clearText() { document.getElementById("textInput").value = ""; updateCounts(); } function copyText() { const text = document.getElementById("textInput").value; navigator.clipboard.writeText(text).then( () => alert("Text copied to clipboard!"), () => alert("Failed to copy text.") ); }