styled-components vs emotion vs glamorous vs styled-jsx
CSS-in-JSライブラリ
styled-componentsemotionglamorousstyled-jsx類似パッケージ:

CSS-in-JSライブラリ

CSS-in-JSライブラリは、JavaScriptの中にCSSを埋め込むことで、スタイルをコンポーネントに直接関連付ける手法を提供します。これにより、スタイルのスコープがコンポーネントに限定され、スタイルの衝突を防ぎ、動的スタイルの適用が容易になります。これらのライブラリは、Reactなどのコンポーネントベースのフレームワークと特に相性が良く、スタイルの管理を効率化します。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
styled-components8,899,79541,0321.84 MB3368日前MIT
emotion761,393---5年前MIT
glamorous03,626-07年前MIT
styled-jsx07,7941.03 MB8310ヶ月前MIT

機能比較: styled-components vs emotion vs glamorous vs styled-jsx

パフォーマンス

  • styled-components:

    Styled-componentsは、CSSをJavaScriptに統合することで、スタイルの適用を効率化し、パフォーマンスを向上させます。特に、スタイルがコンポーネントにスコープされるため、不要なスタイルの生成を防ぎます。

  • emotion:

    Emotionは、スタイルの生成を最適化するため、必要なスタイルのみを生成し、ランタイムでのパフォーマンスを向上させます。特に、スタイルが動的に変更される場合でも、高速なレンダリングを実現します。

  • glamorous:

    Glamorousは、スタイルをコンポーネントに直接結びつけるため、スタイルの適用が迅速で、パフォーマンスに優れています。ただし、複雑なスタイルが多い場合は、パフォーマンスに影響を与える可能性があります。

  • styled-jsx:

    Styled-jsxは、コンポーネントごとにスタイルをスコープするため、スタイルの衝突を防ぎつつ、パフォーマンスを維持します。特に、サーバーサイドレンダリングにおいても優れたパフォーマンスを発揮します。

使いやすさ

  • styled-components:

    Styled-componentsは、スタイルをコンポーネントに直接結びつけることができるため、構造が明確で、使いやすさが高いです。また、テーマ機能を利用することで、スタイルの管理が容易になります。

  • emotion:

    Emotionは、シンプルなAPIを提供しており、直感的に使えるため、初心者でも扱いやすいです。また、柔軟性が高く、さまざまなスタイルの適用方法をサポートしています。

  • glamorous:

    Glamorousは、簡単にスタイルを追加できるため、迅速な開発が可能です。特に、Reactコンポーネントにスタイルを適用する際のシンプルさが魅力です。

  • styled-jsx:

    Styled-jsxは、簡単にスコープ付きスタイルを作成できるため、使いやすさが高いです。特に、Next.jsとの統合がスムーズで、開発者にとって便利です。

テーマ管理

  • styled-components:

    Styled-componentsは、強力なテーマ機能を提供しており、アプリ全体で一貫したスタイルを維持するのに役立ちます。特に、テーマの切り替えがスムーズで、開発者にとって便利です。

  • emotion:

    Emotionは、テーマ機能をサポートしており、アプリ全体で一貫したスタイルを適用するのが容易です。特に、テーマの切り替えが簡単で、動的なスタイル変更が可能です。

  • glamorous:

    Glamorousは、テーマ管理の機能は限定的ですが、スタイルを簡単に適用できるため、特定のテーマに基づいたスタイルの適用は可能です。

  • styled-jsx:

    Styled-jsxは、テーマ管理の機能はあまり強力ではありませんが、スコープ付きスタイルを簡単に作成できるため、特定のテーマに基づいたスタイルの適用は可能です。

スタイルのスコープ

  • styled-components:

    Styled-componentsは、スタイルをコンポーネントにスコープすることができ、スタイルの衝突を防ぎます。これにより、コンポーネントの再利用性が高まります。

  • emotion:

    Emotionは、スタイルをコンポーネントにスコープすることで、スタイルの衝突を防ぎます。これにより、複数のコンポーネントで同じクラス名を使用しても、問題が発生しません。

  • glamorous:

    Glamorousもスタイルをコンポーネントにスコープするため、スタイルの衝突を防ぎます。特に、シンプルな構文でスタイルを適用できるため、使いやすさが向上します。

  • styled-jsx:

    Styled-jsxは、スタイルをコンポーネントにスコープするため、スタイルの衝突を防ぎます。特に、Next.jsとの統合により、サーバーサイドレンダリングでも効果的です。

サーバーサイドレンダリング

  • styled-components:

    Styled-componentsは、サーバーサイドレンダリングに対応しており、初期レンダリング時にスタイルを適用することで、SEOを改善します。特に、クライアントとサーバーで同じスタイルを適用できるため、整合性が保たれます。

  • emotion:

    Emotionは、サーバーサイドレンダリングをサポートしており、初期レンダリング時にスタイルを適切に適用できます。これにより、SEOやパフォーマンスが向上します。

  • glamorous:

    Glamorousは、サーバーサイドレンダリングをサポートしていますが、他のライブラリに比べて設定がやや複雑です。

  • styled-jsx:

    Styled-jsxは、Next.jsとの統合により、サーバーサイドレンダリングを容易に実現できます。これにより、SEOやパフォーマンスが向上します。

選び方: styled-components vs emotion vs glamorous vs styled-jsx

  • styled-components:

    Styled-componentsは、スタイルをコンポーネントに直接結びつけることができるため、コンポーネントの再利用性を高めたい場合に適しています。特に、テーマ機能を利用してアプリ全体のスタイルを一元管理したい場合に便利です。

  • emotion:

    Emotionは、高度なパフォーマンスと柔軟性を提供するため、特に大規模なアプリケーションや複雑なスタイルが必要なプロジェクトに適しています。特に、スタイルを動的に変更する必要がある場合に強力です。

  • glamorous:

    Glamorousは、シンプルさと使いやすさを重視しているため、迅速にスタイルを適用したい場合に適しています。特に、Reactコンポーネントに簡単にスタイルを追加したい開発者に向いています。

  • styled-jsx:

    Styled-jsxは、Next.jsと特に相性が良く、サーバーサイドレンダリングをサポートしているため、SEOを重視するプロジェクトに最適です。また、スコープ付きスタイルを簡単に作成できるため、スタイルの衝突を避けるのに役立ちます。

styled-components のREADME


Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅

downloads: 600k/month gzip size module formats: umd, cjs, esm Code Coverage

Upgrading from v5? See the migration guide.

Utilizing tagged template literals (a recent addition to JavaScript) and the power of CSS, styled-components allow you to write actual CSS code to style your components. It also removes the mapping between components and styles – using components as a low-level styling construct could not be easier!

const Button = styled.button`
  color: grey;
`;

Alternatively, you may use style objects. This allows for easy porting of CSS from inline styles, while still supporting the more advanced styled-components capabilities like component selectors and media queries.

const Button = styled.button({
  color: 'grey',
});

Equivalent to:

const Button = styled.button`
  color: grey;
`;

styled-components is compatible with both React (for web) and React Native – meaning it's the perfect choice even for truly universal apps! It also supports React Server Components (RSC) through automatic runtime detection. See the documentation about React Native for more information.

Supported by Front End Center. Thank you for making this possible!


Docs

See the documentation at styled-components.com/docs for more information about using styled-components!

Quicklinks to some of the most-visited pages:


Example

import React from 'react';

import styled from 'styled-components';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

function MyUI() {
  return (
    // Use them like any other React component – except they're styled!
    <Wrapper>
      <Title>Hello World, this is my first styled component!</Title>
    </Wrapper>
  );
}

This is what you'll see in your browser:


Looking for v5?

The main branch is for the most-current version of styled-components, currently v6. For changes targeting v5, please point your PRs at the legacy-v5 branch.


Built with styled-components

A lot of hard work goes into community libraries, projects, and guides. A lot of them make it easier to get started or help you with your next project! There are also a whole lot of interesting apps and sites that people have built using styled-components.

Make sure to head over to awesome-styled-components to see them all! And please contribute and add your own work to the list so others can find it.


Contributing

If you want to contribute to styled-components please see our contributing and community guidelines, they'll help you get set up locally and explain the whole process.

Please also note that all repositories under the styled-components organization follow our Code of Conduct, make sure to review and follow it.


Badge

Let everyone know you're using styled-componentsstyle: styled-components

[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components)

Contributors

This project exists thanks to all the people who contribute. [Contribute].


Backers

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


Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]


License

Licensed under the MIT License, Copyright © 2016-present Glen Maddern and Maximilian Stoiber.

See LICENSE for more information.


Acknowledgements

This project builds on a long line of earlier work by clever folks all around the world. We'd like to thank Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson & Andrey Sitnik who contributed ideas, code or inspiration.

Special thanks to @okonet for the fantastic logo.