You need to provide className for the wrapper/container as styled-component injecting the styles through it:

const SignupForm = ({ className }) => (
  <form className={className}>
    <input className="input" />
    <button className="button">Button</button>
  </form>
);

const Form = styled(SignupForm)`
  .input {
    background-color: palegreen;
  }

  .button {
    background-color: palevioletred;
  }
`;

Answer from Dennis Vash on Stack Overflow
🌐
styled-components
styled-components.com › docs › advanced
styled-components
If you use the styled(MyComponent) notation and MyComponent does not render the passed-in className prop, then no styles will be applied. To avoid this issue, make sure your component attaches the passed-in className to a DOM node:
Discussions

styled-components vs className for css styling ?

There isn't a standard at this point from what I can tell.

I personally use styled-components and find it much easier. Big benefit being styles related to component are within the same file, so the modularity is good.

Tailwind has been picking up steam, especially good for rapid development.

More on reddit.com
🌐 r/reactjs
26
8
May 21, 2021
Can we use styled components export className ?
const Wrapper = styled.div` &-icon { color: #fff; } ` render() { const cls = Wrapper.getClassName(); return xxx } This saves a lot on the definition of the styled component。 More on github.com
🌐 github.com
23
October 18, 2018
Append custom class names to styled component
Is it possible to have classes added via the className prop of a styled component be appended to the end of the class list instead of the start. Take this button component as an example, which has ... More on github.com
🌐 github.com
6
February 24, 2021
reactjs - How to define className in styled components - Stack Overflow
I'm busy refactoring a React project to use styled components. It's currently using SASS. So, I've got a working component: import React from 'react'; import styled from 'styled-components'; const More on stackoverflow.com
🌐 stackoverflow.com
June 12, 2018
🌐
styled-components
styled-components.com › docs › basics
Styled Components Basic
If you put selectors in without the ampersand, they will refer to children of the component. const Thing = styled.div` color: blue; .something { border: 1px solid; // an element labeled ".something" inside <Thing> display: block; } ` render( <Thing> <label htmlFor="foo-button" className="something">Mystery button</label> <button id="foo-button">What do I do?</button> </Thing> )
🌐
Medium
medium.com › @justiceotuya › how-to-add-classnames-to-styled-components-f1f88518ab51
How to add ClassNames to Styled Components | by Otuya Justice | Medium
February 19, 2020 - The .attrs object also takes functions, that receive the props that the component receives. The return value will be merged into the resulting props as well. ... We use the attrs constructor which exposes the className and then we can bind our className props to the attrs className. we can now style the dynamic classNames accordingly
🌐
Medium
medium.com › @tyson-skiba › readable-class-names-with-styled-components-539ba6ba9310
Readable Classnames with Styled-Components | by Tyson Skiba | Medium
October 10, 2021 - There is however a very simple solution to this problem. By importing from `styled-components/macro` instead of `styled-components` and using babel you are able to get classnames that correlate to the styled component name.
🌐
GitHub
github.com › styled-components › styled-components › issues › 2113
Can we use styled components export className ? · Issue #2113 · styled-components/styled-components
October 18, 2018 - const Wrapper = styled.div` &-icon { color: #fff; } ` render() { const cls = Wrapper.getClassName(); return <Wrapper> <div className={`${cls}-icon`}>xxx</div> </Wrapper> } This saves a lot on the definition of the styled component。
Author   windyGex
🌐
Better Programming
betterprogramming.pub › how-to-control-class-names-in-styled-components-72ed4b165cb9
How to Control Class Names in Styled Components | by Jennifer Fu | Better Programming
July 11, 2022 - How to Control Class Names in Styled Components Babel configuration for styled-components styled-components is a popular library to style React applications. We have introduced what it is and how to …
Find elsewhere
🌐
Josh W. Comeau
joshwcomeau.com › react › demystifying-styled-components
Demystifying styled-components • Josh W. Comeau
When we render PinkButton, the Tag variable is equal to our Button component. PinkButton will generate a unique class name (def456), and pass that as the className prop to Button. If you're confused by this process, you're not alone; we've entered the mindbending realm of recursion, where styled-components are rendering styled-components.
🌐
Hutchida
hutchida.com › posts › styled-components-vs-classnames
Styled Components vs Classnames | HUTCHIDA
May 2, 2023 - This is also configured at the top level in the component, usually on the wrapper, so that any parent can pass down a class and have it applied. You cannot, as far as I'm aware, pass dynamic props down to the classes. For example, if you wanted to set the source for a background image on a div, you would normally do this with css, but maybe you wouldn't want to hardcode it. The only way you could do this if you were using classnames, is to set an inline style on the element like this:
🌐
DEV Community
dev.to › elijahtrillionz › complete-guide-on-how-to-use-styled-components-in-react-360c
Complete Guide On How To Use Styled-components In React - DEV Community
February 19, 2022 - You must pass in the className prop in the parent element of the component to be styled because with it styled component can apply the given styles to the component. Apart from custom components, you can also style components that you did not ...
🌐
GitHub
github.com › emotion-js › emotion › issues › 2268
Append custom class names to styled component · Issue #2268 · emotion-js/emotion
February 24, 2021 - Take this button component as an example, which has a custom class added. const Button = styled('button')(...); <Button className="my-class">Click Me</Button>
Author   iamturner
🌐
Robusta Code
robusta.io › blog › javascript › applying-correctly-classname-with-styled-components
Robusta.io: Applying correctly className with Styled components
November 5, 2020 - The problem is that styled(Comp) is effective only if Comp is already a styled component. To achieve this, you must add the className to MyButton
🌐
Softchris
softchris.github.io › pages › react-styled-components.html
Styled components, the styling library for your React apps you don’t want to be without
As you can see above calling the styled() function means that it under the hood produces a className that it injects into our component that we need to set to our top-level element, for it to take effect.
🌐
N's Blog
naura.hashnode.dev › how-to-pass-classname-to-styled-components-in-react
How to Pass className to Styled-Components in React
September 16, 2022 - So now we can write regular CSS with classNames inside our <Badge /> component; export const Badge = styled.div.attrs((props) => ({ className: props.className }))` /* ...existing styles */ &.react { background-color: #f2fbdc; color: #a7c957; } &.styled-components { background-color: #f9f5ff; color: #6941c6; } &.web-dev { background-color: #fdf2fa; color: #c11574; } `;
🌐
egghead.io
egghead.io › lessons › react-style-react-components-with-classname-and-in-line-styles
Style React Components with className and In Line Styles | egghead.io
[05:00] In review, to style a React component, you can use the classname prop to assign classnames used in regular CSS styles, and you can use the style prop which accepts an object of CSS.
Published   October 4, 2017
🌐
Emotion
emotion.sh › docs › styled
Emotion – Styled Components
styled can style any component as long as it accepts a className prop.
🌐
GitHub
github.com › styled-components › styled-components › issues › 3179
Feature Request: Support for class props other than className · Issue #3179 · styled-components/styled-components
June 18, 2020 - It has both a className prop for the dialog proper and a prop for the surrounding portal component portalClassName. If you are using styled components you are unable to make use of portalClassName, and instead have to rely on global styles which is not preferable.
Author   maclockard
🌐
Daggala
daggala.com › easily-debug-styled-components-random-classes
Easily debug styled-components' random classes - Daggala
Let’s say we’ve a component ... styled-component · And this is how the DOM tree will look in the browser (not very descriptive) You can see when we’re using vanilla CSS, we see the class name, so we can easily find that class in our code and modify its styles. But when we use SC we get this random ljsdfjaasfdjlsf classname which can ...