Notes
HTML
CSS
JS
Tools
Code Snippets
HTML Entity
About
Contact Us
Track Word, Character, and Line Count Dynamically with Text Area in HTML, CSS, and JS
HTML
CSS
JS
Output
HTML
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Track Word, Character, and Line Count Dynamically with Text Area in HTML, CSS, and JS</title> </head> <body> <textarea id="textAreaId" placeholder="Type your word here..."></textarea> <div class="countable-all"> <p>Word Count: <span id="word-counts">0</span></p> <p>Character Count: <span id="char-counts">0</span></p> <p>Line Count: <span id="line-counts">0</span></p> </div> </body> </html>
Copied
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Track Word, Character, and Line Count Dynamically with Text Area in HTML, CSS, and JS</title> </head> <body> <textarea id="textAreaId" placeholder="Type your word here..."></textarea> <div class="countable-all"> <p>Word Count: <span id="word-counts">0</span></p> <p>Character Count: <span id="char-counts">0</span></p> <p>Line Count: <span id="line-counts">0</span></p> </div> </body> </html>
CSS
*{ margin: 0; padding: 0; box-sizing: border-box; } textarea { display: block; width: 95%; height: 200px; border-radius: 10px; border: 2px solid #58d8a3; outline: none; box-shadow: none; padding: 10px; margin: 15px auto 0 auto; resize: none; } textarea:focus { border: 2px solid #58d8a3; outline: none; box-shadow: none; } .countable-all { display: inline-flex; gap: 1rem; background: #58d8a3; padding: 5px 15px; border-radius: 5px; margin: 10px 3%; } .countable-all p { margin: 0; font-size: 18px; color: #fff; } .countable-all p span { font-weight: 700; } @media (max-width:450px) { .countable-all { display: inline-block; } .countable-all p { margin-bottom: 5px; } .countable-all p:last-child { margin-bottom: 5px; } }
Copied
*{ margin: 0; padding: 0; box-sizing: border-box; } textarea { display: block; width: 95%; height: 200px; border-radius: 10px; border: 2px solid #58d8a3; outline: none; box-shadow: none; padding: 10px; margin: 15px auto 0 auto; resize: none; } textarea:focus { border: 2px solid #58d8a3; outline: none; box-shadow: none; } .countable-all { display: inline-flex; gap: 1rem; background: #58d8a3; padding: 5px 15px; border-radius: 5px; margin: 10px 3%; } .countable-all p { margin: 0; font-size: 18px; color: #fff; } .countable-all p span { font-weight: 700; } @media (max-width:450px) { .countable-all { display: inline-block; } .countable-all p { margin-bottom: 5px; } .countable-all p:last-child { margin-bottom: 5px; } }
JS
const textBoxArea = document.getElementById('textAreaId'); const wordCountArea = document.getElementById('word-counts'); const charCountArea = document.getElementById('char-counts'); const lineCountArea = document.getElementById('line-counts'); textBoxArea.addEventListener('input', function () { let text = textBoxArea.value; // number of words count let words = text.match(/\S+/g); wordCountArea.innerText = words ? words.length : 0; // number of characters count charCountArea.innerText = text.length; // number of lines count let lines = text.split(/\r?\n/); lineCountArea.innerText = lines.length; });
Copied
const textBoxArea = document.getElementById('textAreaId'); const wordCountArea = document.getElementById('word-counts'); const charCountArea = document.getElementById('char-counts'); const lineCountArea = document.getElementById('line-counts'); textBoxArea.addEventListener('input', function () { let text = textBoxArea.value; // number of words count let words = text.match(/\S+/g); wordCountArea.innerText = words ? words.length : 0; // number of characters count charCountArea.innerText = text.length; // number of lines count let lines = text.split(/\r?\n/); lineCountArea.innerText = lines.length; });
Output
Our Courses
HTML 5
CSS
JavaScript
MySql
PHP
Laravel
Bootstrap
Programming Tutorial
PHP
JavaScript
HTML
Laravel
MySQL
JQuery
CSS
Git
Bootstrap
Vue JS
Android
Python
Server
Code Snippets
Chat Box
Range Slider
Radio Button
Select Box
Nav Bar
Other
Testimonial
Carousel
Logo
Loader
Lightbox
Forms
Popup
Table
HTML Course Code
HTML Entity
↑→ Arrows
$¢ Currency
Aö Letters
%+ Math
1¾ Numbers
&— Punctuation
©™ Symbols
Best Of
Internet
Technology
Health
Travel
Onine Tools
CSS Minifier
Text Converter
Age Calculator
Pincode Details
Whiteboard
PDF to Text
Gradient Generator
PX to REM Converter
REM to PX Converter
PX to EM Converter
EM to PX Converter
WEBP Converter
Latest & Upcoming movies
Bollywood
Hollywood
Tamil
Telgu
Bangla
Web Series
Notes
HTML
CSS
JS