styling react-select using classes

Jane Fred picture Jane Fred · Aug 29, 2019 · Viewed 9.4k times · Source

I am using react-select in my code. https://www.npmjs.com/package/react-select

I want to style my drop down using classNames, so that I referred https://react-select.com/styles. The DOM structure of react slect is shown in the link.

How can I style the react-select using classNames?

Can anyone show a sample code?

Answer

Tim Gerhard picture Tim Gerhard · Aug 29, 2019

According to the documentation

If you provide the className prop to react-select, the SelectContainer will be given a className based on the provided value.

So it should work like this:

<Select className="abc" .... />

Then you can use your classname as usual.

.abc {
color: red;
}

You can also use classNamePrefix

by specifing a classNamePrefix, react-select will render all classNames with your prefix. If you use this:

<Select className="abc" classNamePrefix="react-select" ... />

Your Select will automatically render a class structure like this: enter image description here