File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed
Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Character Counter App</ title >
6+ < style >
7+ body {
8+ font-family : system-ui, Arial;
9+ display : flex;
10+ flex-direction : column;
11+ align-items : center;
12+ justify-content : center;
13+ height : 100vh ;
14+ background : # f3f4f6 ;
15+ }
16+ .container {
17+ background : white;
18+ padding : 25px 30px ;
19+ border-radius : 12px ;
20+ box-shadow : 0 5px 20px rgba (0 , 0 , 0 , 0.1 );
21+ width : 350px ;
22+ text-align : center;
23+ }
24+ textarea {
25+ width : 100% ;
26+ height : 100px ;
27+ font-size : 15px ;
28+ border-radius : 8px ;
29+ padding : 10px ;
30+ resize : none;
31+ border : 1px solid # d1d5db ;
32+ }
33+ p {
34+ margin-top : 10px ;
35+ font-size : 14px ;
36+ }
37+ .count {
38+ font-weight : bold;
39+ }
40+ .red {
41+ color : # ef4444 ;
42+ }
43+ </ style >
44+ </ head >
45+ < body >
46+ < div class ="container ">
47+ < h3 > 📝 Character Counter</ h3 >
48+ < textarea id ="textInput " placeholder ="Type your message... "> </ textarea >
49+ < p > < span id ="charCount " class ="count "> 0</ span > / < span id ="maxCount "> 100</ span > </ p >
50+ </ div >
51+
52+ < script >
53+ const textarea = document . getElementById ( "textInput" ) ;
54+ const charCount = document . getElementById ( "charCount" ) ;
55+ const maxCount = document . getElementById ( "maxCount" ) ;
56+ const limit = 100 ;
57+
58+ maxCount . textContent = limit ;
59+
60+ textarea . addEventListener ( "input" , ( ) => {
61+ const length = textarea . value . length ;
62+ charCount . textContent = length ;
63+
64+ if ( length > limit ) {
65+ charCount . classList . add ( "red" ) ;
66+ textarea . style . borderColor = "#ef4444" ;
67+ } else {
68+ charCount . classList . remove ( "red" ) ;
69+ textarea . style . borderColor = "#d1d5db" ;
70+ }
71+ } ) ;
72+ </ script >
73+ </ body >
74+ </ html >
You can’t perform that action at this time.
0 commit comments