CSS In JS

  • CSS is written inside javascript, the common practice includes styled component, inline css with javascript

  • It is actually generated class behind the scene

  • Here is the example with using emotion library

import { css } from '@emotion/react'

const color = 'white'

render(
  <div
    css={css`
      padding: 32px;
      background-color: hotpink;
      font-size: 24px;
      border-radius: 4px;
      &:hover {
        color: ${color};
      }
    `}
  >
    Hover to change color.
  </div>
)

Last updated

Was this helpful?