<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!-- Google Font -->
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap"
rel="stylesheet"
/>
<!-- Stylesheet -->
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="wrapper">
<div class="container">
<textarea
id="input-textarea"
rows="12"
placeholder="Start Typing here..."
></textarea>
</div>
<div class="count">
<div>
<h5 id="word-count">0</h5>
<p>Words</p>
</div>
<div>
<h5 id="charac-count">0</h5>
<p>Characters</p>
</div>
</div>
</div>
<!-- Script -->
<script src="script.js"></script>
</body>
</html>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
background-color: #8b5ceb;
}
.wrapper {
position: absolute;
width: 90vmin;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
}
.container {
background-color: #ffffff;
padding: 50px 30px 80px 30px;
border-radius: 8px;
box-shadow: 0 30px 50px rgba(30, 21, 49, 0.3);
}
textarea {
width: 100%;
border: none;
resize: none;
outline: none;
font-size: 16px;
line-height: 28px;
color: #0e101a;
}
.count {
background-color: #000000;
width: 80%;
padding: 20px;
position: relative;
transform: translate(-50%, -50%);
left: 50%;
display: flex;
justify-content: space-around;
text-align: center;
border-radius: 5px;
box-shadow: 0 20px 40px rgba(30, 21, 49, 0.4);
}
.count p {
color: #a0a0c0;
}
.count h5 {
color: #ffffff;
font-size: 32px;
}
let inputTextArea = document.getElementById("input-textarea");
let characCount = document.getElementById("charac-count");
let wordCount = document.getElementById("word-count");
inputTextArea.addEventListener("input", () => {
characCount.textContent = inputTextArea.value.length;
let txt = inputTextArea.value.trim();
wordCount.textContent = txt.split(/\s+/).filter((item) => item).length;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.