styled-components vs emotion vs rebass vs theme-ui
スタイリングライブラリ
styled-componentsemotionrebasstheme-ui類似パッケージ:

スタイリングライブラリ

スタイリングライブラリは、Reactなどのフレームワークでコンポーネントのスタイルを効率的に管理するためのツールです。これらのライブラリは、CSSをJavaScriptで扱うことを可能にし、スタイルの再利用性やコンポーネントのスコープを向上させます。特に、動的スタイルやテーマの管理が容易になるため、開発者はより柔軟でメンテナンス性の高いコードを書くことができます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
styled-components9,721,16141,0232 MB124日前MIT
emotion0---5年前MIT
rebass07,907-976年前MIT
theme-ui05,39580.4 kB624ヶ月前MIT

機能比較: styled-components vs emotion vs rebass vs theme-ui

スタイルの適用方法

  • styled-components:

    Styled-componentsでは、スタイルをコンポーネントとして定義し、コンポーネントのスコープ内でスタイルを管理します。これにより、スタイルの衝突を防ぎ、再利用可能なスタイルを作成できます。

  • emotion:

    Emotionは、CSS-in-JSのアプローチを採用しており、JavaScript内でスタイルを定義できます。これにより、動的なスタイルを簡単に作成でき、条件に応じたスタイルの変更が容易です。

  • rebass:

    Rebassは、スタイルをコンポーネントに直接適用するシンプルな方法を提供します。デフォルトのテーマに基づいて、迅速にスタイルを適用できるため、プロトタイピングに非常に便利です。

  • theme-ui:

    Theme UIは、テーマを中心に設計されており、テーマのプロバイダーを使用して、アプリ全体で一貫したスタイルを適用できます。これにより、テーマの変更が容易になり、デザインの一貫性を保つことができます。

パフォーマンス

  • styled-components:

    Styled-componentsは、スタイルをコンポーネントに結びつけることで、不要な再レンダリングを防ぎ、パフォーマンスを最適化します。また、スタイルのキャッシング機能により、スタイルの再利用が促進されます。

  • emotion:

    Emotionは、スタイルを動的に生成する際に最適化されており、必要なスタイルのみを生成するため、パフォーマンスが高いです。また、CSSのバンドルサイズを最小限に抑えることができます。

  • rebass:

    Rebassは、軽量なスタイリングライブラリであり、必要なスタイルのみをインポートすることで、アプリケーションのパフォーマンスを向上させます。

  • theme-ui:

    Theme UIは、テーマの再利用性を高めることで、パフォーマンスを向上させます。テーマを一元管理することで、スタイルの適用が効率的になります。

テーマ管理

  • styled-components:

    Styled-componentsは、テーマのプロバイダーを使用して、アプリ全体で一貫したスタイルを適用できます。テーマの変更が容易で、スタイルの再利用性が高まります。

  • emotion:

    Emotionは、テーマの管理をサポートしており、テーマプロバイダーを使用して、アプリ全体で一貫したスタイルを適用できます。

  • rebass:

    Rebassは、デフォルトのテーマを提供し、カスタマイズが容易です。テーマの変更が簡単で、プロジェクト全体に適用できます。

  • theme-ui:

    Theme UIは、テーマの管理を中心に設計されており、テーマのプロバイダーを使用して、アプリ全体で一貫したスタイルを適用できます。特に、デザインシステムの構築に役立ちます。

学習曲線

  • styled-components:

    Styled-componentsは、CSSの知識があれば比較的簡単に学習できます。コンポーネントベースのアプローチにより、スタイルの管理が直感的です。

  • emotion:

    Emotionは、CSS-in-JSの概念を理解する必要があるため、初めてのユーザーには少し学習曲線がありますが、柔軟性が高いため、習得すれば強力なツールとなります。

  • rebass:

    Rebassは、シンプルで直感的なAPIを提供しており、学習曲線が緩やかです。特に、デフォルトのテーマを使用することで、すぐにスタイルを適用できます。

  • theme-ui:

    Theme UIは、テーマの概念を理解する必要がありますが、テーマプロバイダーを使用することで、スタイルの適用が容易になります。特に、デザインシステムに慣れている開発者には適しています。

エコシステムとサポート

  • styled-components:

    Styled-componentsは、非常に人気があり、広範なエコシステムを持っています。多くのプラグインや拡張機能が利用可能で、サポートも充実しています。

  • emotion:

    Emotionは、広範なコミュニティとサポートがあり、ドキュメントも充実しています。多くのプロジェクトで使用されているため、情報が豊富です。

  • rebass:

    Rebassは、シンプルさを重視したライブラリであり、コミュニティも活発です。特に、デザインシステムの構築に役立つ情報が多くあります。

  • theme-ui:

    Theme UIは、テーマ管理に特化したライブラリであり、デザインシステムに関連するリソースが豊富です。特に、テーマのカスタマイズに関する情報が多くあります。

選び方: styled-components vs emotion vs rebass vs theme-ui

  • styled-components:

    Styled-componentsは、コンポーネントベースのスタイルの管理を重視する場合に選ぶべきです。特に、スタイルをコンポーネントに直接結びつけることで、スタイルのスコープを明確にし、再利用性を高めることができます。

  • emotion:

    Emotionは、スタイルの柔軟性とパフォーマンスを重視する場合に最適です。特に、CSS-in-JSのアプローチを採用し、動的スタイルを簡単に作成できるため、複雑なスタイリングが必要なプロジェクトに向いています。

  • rebass:

    Rebassは、シンプルで軽量なスタイリングを求める場合に適しています。特に、デフォルトのテーマを持ち、迅速なプロトタイピングが可能なため、スタイルの一貫性を保ちながら開発を進めたい場合に選択するべきです。

  • theme-ui:

    Theme UIは、テーマの管理とカスタマイズを重視する場合に最適です。特に、テーマのプロバイダーを使用して、アプリ全体で一貫したスタイルを適用できるため、デザインシステムを構築する際に役立ちます。

styled-components のREADME


Fast, expressive styling for React.
Server components, client components, streaming SSR, React Native—one API.

npm downloads gzip size

styled-components is largely maintained by one person. Please help fund the project for consistent long-term support and updates: Open Collective


Style React components with real CSS, scoped automatically and delivered only when needed. No class name juggling, no separate files, no build step required.

  • Works everywhere React runs. Server components, client components, streaming SSR, and React Native—same API, automatic runtime detection.
  • Full CSS, no compromises. Media queries, pseudo-selectors, nesting, keyframes, global styles. If CSS supports it, so does styled-components.
  • TypeScript-first. Built-in types ship with the package. Props flow through to your styles with full inference—no @types install, no manual generics.
  • <13kB gzipped. Small enough to disappear in your bundle. No build plugin required.

Install

npm install styled-components
pnpm / yarn
pnpm add styled-components
yarn add styled-components

Quick examples

Dynamic props

Vary styles based on component props. Prefix transient props with $ to keep them off the DOM.

import styled from 'styled-components';

const Button = styled.button<{ $primary?: boolean }>`
  background: ${props => (props.$primary ? 'palevioletred' : 'white')};
  color: ${props => (props.$primary ? 'white' : 'palevioletred')};
  font-size: 1em;
  padding: 0.25em 1em;
  border: 2px solid palevioletred;
  border-radius: 3px;
`;

<Button>Normal</Button>
<Button $primary>Primary</Button>

Extending styles

Build variants on top of existing styled components.

const TomatoButton = styled(Button)`
  background: tomato;
  color: white;
  border-color: tomato;
`;

Polymorphic as prop

Swap the rendered element without changing styles.

// Renders a <a> tag with Button styles
<Button as="a" href="/home">Link Button</Button>

Pseudos and nesting

Use & to reference the component's generated class name—works with pseudo-classes, pseudo-elements, and nested selectors.

const Input = styled.input`
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.5em;

  &:focus {
    border-color: palevioletred;
    outline: none;
  }

  &::placeholder {
    color: #aaa;
  }
`;

Animations

Define @keyframes once, reference them across components. Names are scoped automatically.

import styled, { keyframes } from 'styled-components';

const rotate = keyframes`
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
`;

const Spinner = styled.div`
  animation: ${rotate} 1s linear infinite;
  width: 40px;
  height: 40px;
  border: 3px solid palevioletred;
  border-top-color: transparent;
  border-radius: 50%;
`;

Theming

Share design tokens across your app via React context. Every styled component receives props.theme.

import styled, { ThemeProvider } from 'styled-components';

const theme = {
  fg: 'palevioletred',
  bg: 'white',
};

const Card = styled.div`
  background: ${props => props.theme.bg};
  color: ${props => props.theme.fg};
  padding: 2em;
`;

<ThemeProvider theme={theme}>
  <Card>Themed content</Card>
</ThemeProvider>

RSC-compatible themes

createTheme turns your tokens into CSS custom properties. Class name hashes stay stable across theme variants—no hydration mismatch when switching light/dark.

import styled, { createTheme, ThemeProvider } from 'styled-components';

const { theme, GlobalStyle: ThemeVars } = createTheme({
  colors: {
    fg: 'palevioletred',
    bg: 'white',
  },
  space: {
    md: '1rem',
  },
});

const Card = styled.div`
  color: ${theme.colors.fg};       /* var(--sc-colors-fg, palevioletred) */
  background: ${theme.colors.bg};
  padding: ${theme.space.md};
`;

// Render <ThemeVars /> at the root to emit the CSS variable declarations
// Pass the theme to ThemeProvider for stable hashes
<ThemeProvider theme={theme}>
  <ThemeVars />
  <Card>Token-driven content</Card>
</ThemeProvider>

Shared styles with css

Extract reusable style blocks to share across components or apply conditionally.

import styled, { css } from 'styled-components';

const truncate = css`
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
`;

const Label = styled.span`
  ${truncate}
  max-width: 200px;
`;

Styling third-party components

Wrap any component that accepts a className prop.

import styled from 'styled-components';
import { Link } from 'react-router-dom';

const StyledLink = styled(Link)`
  color: palevioletred;
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
`;

Global styles

Inject app-wide CSS like resets and font faces. Supports theming and dynamic updates.

import { createGlobalStyle } from 'styled-components';

const GlobalStyle = createGlobalStyle`
  body {
    margin: 0;
    font-family: system-ui, sans-serif;
  }
`;

// Render <GlobalStyle /> at the root of your app

Attrs

Set default or static HTML attributes so consumers don't have to.

const PasswordInput = styled.input.attrs({
  type: 'password',
  placeholder: 'Enter password',
})`
  border: 1px solid #ccc;
  padding: 0.5em;
`;

Documentation

Community

Contributing guidelines | Code of Conduct | awesome-styled-components

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! [Become a backer]

Sponsors

Support this project by becoming a sponsor. [Become a sponsor]

Acknowledgements

This project builds on earlier work by Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson, and Andrey Sitnik. Special thanks to @okonet for the logo.

License

Licensed under the MIT License, Copyright © 2016-present styled-components contributors. See LICENSE for details.