Apply Styles to the Application for Character Counter
The next step is to add styles to each element to make it visually appealing using CSS. We can create n styling files one for each component. In this project, we will create two CSS files, one for the character counter component and another for the App component.
- Modify the character counter component to add styling for each element. Using the
classNameattribute, we can match the styling to the element. Make sure to import the style file into the component.
// CharacterCounter.jsx
import "./CharacterCounter.css";
function CharacterCounter() {
return (
<div className="container">
<div className="input">
<textarea
id="input"
placeholder="Enter a text"
value={text}
/>
</div>
<div className="result">
<div className="character-count">
<span id="characterCount">0</span>
<span>Characters</span>
</div>
<div className="character-count-without-spaces">
<span id="characterCount">0</span>
<span>Characters (Excluding Spaces)</span>
</div>
<div className="word-count">
<span id="wordCount">0</span>
<span>Words</span>
</div>
</div>
</div>
);
}
export default CharacterCounter;- The next step is to create a styling file for character counter. Create a file in the component folder
ChacterCounter.css. And write styles for each element.
/* ChacterCounter.css */
/* Main body styling */
body{
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: rgb(224, 223, 223);
}
/* Main container styling */
.container{
width: max-content;
}
/* Text area styling */
#input{
resize: none;
height: 200px;
width: 700px;
border: 3px solid black;
padding: 2px;
margin: 25px 0;
font-size: 1rem;
}
/* Display area styling */
.result{
display: flex;
flex-direction: row;
justify-content: space-between;
font-size: 1.5rem;
}- Now, let’s add some styling to the App component.
// App.js
import "./App.css";
import CharacterCounter from "./components/CharacterCounter";
function App() {
return (
<div className="App">
<div className="header">
<h1 className="title">Character Counter App</h1>
</div>
<CharacterCounter />
<a href="https://www.guvi.in/" className="copywright">
Made by Guvi💚
</a>
</div>
);
}
export default App;- Modify the
App.cssfile to include new stylings.
/* App.css */
*{
margin: 0;
padding: 0;
}
.App{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.title{
font-size: 2rem;
margin: 20px;
}
.copywright{
margin-top: 50px;
}- Once you add the styling, the application will look like the below output.


