Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
Post image 6
1 / 6
0

How to customize colors in dark and light modes in Material UI

DEV Community: materialui·Nguyễn Minh Chí·about 1 month ago
#hrznFUB0
#dev#c0c0c0#class#code#auto#highlight
Reading 0:00
15s threshold

When we use UI libraries like Material UI in our React project, sometimes we need to customize color in both dark and light modes instead of using its default colors. This post will instruct you how to do that. First, make sure you have installed Material UI if you have not installed it yet, let's type: npm install @mui/material @emotion/react @emotion/styled Next, we will create a file named custom-themes.ts : // custom-themes.ts import { experimental_extendTheme as extendTheme } from " @mui/material/styles " ; //If you are using TypeScript, you must declare your custom color's name in both PaletteOptions and Palette in module "@mui/material/styles" declare module " @mui/material/styles " { interface PaletteOptions { " bg-text-input " : string ; } interface Palette { " bg-text-input " : string ; } } const customTheme = extendTheme ({ cssVarPrefix : "" , colorSchemes : { light : { palette : { " bg-text-input " : " #C0C0C0 " , // Specify color in light mode for "bg-text-input" }, }, dark : { palette : { "…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More