Add Styling to defaultValue in textarea in React
Last Updated :
08 Apr, 2025
Textarea in ReactJS can be styled to defaultValue using various approaches such as inline styling and Styled Components. Inline styling allows for direct CSS property application within JSX, while Styled Components provides a structured way to define and manage CSS styles within React components.
Prerequisites
Below are the approaches to add styling to defaultValue in textarea:
Steps to Create a React App
Step 1: Set up a new React project using:
npx create-react-app myapp
Step 2: Navigate to the root of the project using the following command:
cd myapp
Step 3: Install the required packages using the below command:
npm install styled-components
Project Structure:

The Updated package.json will look like:
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^6.1.11",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Using Inline Styling
In this approach, we are using inline styles directly within the JSX to style the defaultValue in the textarea.
Example: The below example uses Inline Styling to add styling to defaultValue in textarea in ReactJS.
JavaScript
// App.js
import React from 'react';
function App() {
const defaultValue =
"Welcome to GeeksforGeeks! This is an example of inline styled textarea.";
return (
<div style={{
padding: '20px',
fontFamily: 'Arial, sans-serif'
}}>
<h3>Using Inline Styling</h3>
<textarea
defaultValue={defaultValue}
style={{
width: '50%',
height: '150px',
padding: '10px',
border: '1px solid #2E8B57',
borderRadius: '5px',
fontSize: '20px',
color: 'red',
backgroundColor: '#f9f9f9',
}}
/>
</div>
);
}
export default App;
Start your application using the following command:
npm install styled-components
Output:
OutputUsing Styled Components
In this approach, we are using Styled Components in React to add styling to the defaultValue in a textarea. Styled Components allow us to define CSS styles directly within our React components, making it easy to create reusable and maintainable styled elements. The StyledTextarea component encapsulates the styling for the textarea, including properties like width, height, padding, border, border-radius, font-size, color, and background-color.
Example: The below example uses Styled Components to Add styling to defaultValue in textarea in ReactJS.
JavaScript
// App.js
import React from 'react';
import styled from 'styled-components';
const Container = styled.div`
padding: 20px;
font-family: Arial, sans-serif;
`;
const Title = styled.h1`
color: #2E8B57;
`;
const Subtitle = styled.h3`
color: #333;
`;
const StyledTextarea = styled.textarea`
width: 50%;
height: 150px;
padding: 10px;
border: 2px solid #2E8B57;
border-radius: 8px;
font-size: 16px;
color: #333;
background-color: #f9f9f9;
margin-bottom: 20px;
`;
function App() {
const defaultValue =
"Welcome to GeeksforGeeks! This is an example of Styled Components styled textarea.";
return (
<Container>
<Subtitle>Using Styled Components</Subtitle>
<StyledTextarea defaultValue={defaultValue}
style={{ backgroundColor: '#f5f5f5', color: '#2E8B57' }} />
<StyledTextarea defaultValue={defaultValue}
style={{ border: '2px dotted #2E8B57', borderRadius: '10px' }} />
</Container>
);
}
export default App;
Output:
Output
Similar Reads
HTML | DOM Textarea defaultValue property
The DOM Textarea defaultValue Property is used to set or return the default value of the textarea field. Syntax: It is used to return the defaultValue property.textareaObject.defaultValueIt is used to set the defaultValue property:textareaObject.defaultValue = text/value Property Values: text: It sp
2 min read
How to add styles to autocomplete in ReactJS ?
Autocomplete functionality in web applications is common for predictive user input. This article focuses on enhancing the visual appearance of ReactJS autocomplete components using Material-UI's package, offering customization options for seamless integration with the overall application design.Prer
3 min read
How to Disable Text Selection in ReactJS ?
In this article, we will see how to disable the text selection in ReactJS. Prerequisites:Introduction to ReactReact HooksNPM or NPXWeb applications ofteÂn provide a valuable feature called text seleÂction, enabling users to easily highlight and copy content from a webpage. However, there are situat
4 min read
How to add Input Slider in React JS ?
We will learn how to add an input slider in React JS. React is a free and open-source front-end JavaScript library for building user interfaces or UI components. It was introduced by Facebook and a community of individual developers and companies. Prerequisites:Node JS or NPMReact JSReact useStateAp
2 min read
How to create Bold Specific Text In React JS ?
ReactJS has eÂmerged as one of the most widely adopted JavaScript libraries for deÂsigning user interfaces. TheÂy often encounter scenarios that demand speÂcialized text styling capabilities. This includeÂs the need to eÂmphasize certain words or phrases by applying bold formatting. In this article
3 min read
ReactJS Semantic UI Textarea Addons
Semantic UI is a modern framework used in developing seamless designs for the website, It gives the user a lightweight experience with its components. It uses the predefined CSS, JQuery language to incorporate in different frameworks. In this article we will know how to use Textarea Addons in ReactJ
2 min read
HTML DOM Input Text defaultValue Property
The Input Text defaultValue Property in HTML DOM is used to set or return the default value of the Text Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicate the default value and the value contain
2 min read
How to add custom filter in search Box in ReactJS?
The custom filter means adding our own business login to filter the options shown in searchbox or any dropdown menu. Material UI for React has this component available for us and it is very easy to integrate. We can create our own custom filter for options in ReactJS using the following approach. Cr
2 min read
How to create a textarea component in MATLAB
Matlab offers tools for developing GUI applications. It provides functions that can create TextFields, Labels, Buttons, and many more, along with properties to manipulate the components. In this article, we will learn to create a TextArea Component using Matlab. Creating a textarea componentA Text A
4 min read
How to Add Auto-Complete Search Box in ReactJS?
An autocomplete search box is a user interface feature that offers suggestions as users type their queries. It enhances the user experience by providing real-time suggestions and help users find what they're looking for more quickly. In this article, we will explore how to implement an autocomplete
5 min read