How to change mui textfield text color in react js?
November 06, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
To change the text color in mui textfield, set color: #580fce !important;
in .MuiInputBase-root
for text color.
Today, I am going to show you, how to change mui textfield text color in react js mui textfield.
I targeted MuiInputBase-root with the nested selector. Notice the spacing between the & and the class name. This means the selector is looking for a child or the root element.
To change the color of the text textfield do this
.MuiInputBase-root {
color: #580fce !important;
};
Installation
Install the following packages to use mui textfield in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
MUI material textfield change text color example
To change the color of the font, the class .MuiInputBase-root
has to be used.
App.js
import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import "./App.css"
export default function CustomizedInputs() {
return (
<Box
component="form"
noValidate
sx={{
display: 'grid',
gridTemplateColumns: { sm: '1fr 1fr' },
gap: 2,
}}
>
<TextField id="outlined-basic" label="Outlined" variant="outlined" />
<TextField id="filled-basic" label="Filled" variant="filled"/>
<TextField id="standard-basic" label="Standard" variant="standard"/>
</Box>
);
}
App.css
.MuiInputBase-root {
color: #580fce !important;
};
In the above code example, I have used the @mui/material
TextField component and changed the color of the text of all types of MUI Textfield.
Check the output of the above code example.
All the best 👍