• Stars
    star
    245
  • Rank 164,713 (Top 4 %)
  • Language
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a short doc comparing the popular CSS-in-JS libraries styled-components and emotion

styled-components-vs-emotion

Last updated by @JuanmaMenendez on October 25th, 2019 A short doc comparing the popular CSS-in-JS libraries styled-components and emotion. For a more detailed comparison, see:

Brief Description

styled-components

Utilising tagged template literals (a recent addition to JavaScript) and the power of CSS, styled-components allows 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!

emotion

Emotion is a performant and flexible CSS-in-JS library. Building on many other CSS-in-JS libraries, it allows you to style apps quickly with string or object styles. It has predictable composition to avoid specificity issues with CSS. With source maps and labels, Emotion has a great developer experience and great performance with heavy caching in production.

Functionality

The APIs of the two libraries have converged over time. Both let you create a component with styling specified via CSS, or via object notation. (Styled Components added the latter capability in May 2018.)

styled-components

// CSS syntax in tagged template literal
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`
render(<Title>Hiya!</Title>)

// Object syntax
const button = styled.button({
  fontSize: '1.5em',
  textAlign: 'center',
  color: 'palevioletred'
});

emotion

// CSS syntax in tagged template literal

const Button = styled.button`
  padding: 32px;
  background-color: hotpink;
  font-size: 24px;
  border-radius: 4px;
  color: black;
  font-weight: bold;
  &:hover {
    color: white;
  }
`

render(<Button>Hey! It works.</Button>)

---

render(
  <h1
    className={css`
      font-size: 1.5em;
      text-align: center;
      color: palevioletred;
    `}
  >
    Hiya!
  </h1>
)

// Object syntax
const titleStyles = css({
  fontSize: '1.5em',
  textAlign: 'center',
  color: 'palevioletred'
})

render(<h1 className={titleStyles}>Hiya!</h1>)

Comparison

Here's how the two libraries compare based on features and stats:

Features - at parity

This information was taken from the documentation websites.

Library Attaching Props? Media Queries? Global Styles? Nested Selectors? Server Side Rendering? Theming Support? Composition?
styled-components Yes Yes Yes Yes Yes Yes Yes
emotion Yes Yes Yes Yes Yes Yes Yes

Stats

These numbers were pulled on October 18th, 2019.

Library Creation Date Last Updated (GitHub) Size Repo Stars # of Contributors Community Size (Spectrum)
styled-components August 16th, 2016 8 days ago ? 14.6kb ? 26,197 252 10,113
emotion May 27th, 2017 6 days ago ? 8.9kb ? 9,118 184 479

Worthy Notes

  • emotion performed faster than styled-components back in March 12th when a comparison was done over all CSS-in-JS libraries. However, maintainers of styled-components are actively improving performance and say they are within 0.5-2x emotion's times.
  • Kent C. Dodds recommended emotion over styled-components in this tweet saying that it's smaller and faster.

Contributions

If you see a typo or something that is out-of-date or incorrect, please submit a PR and I will happily update this doc.

More Repositories

1

twitter-stripe-mrr

A Node script that calculates your total monthly revenue in Stripe and updates your Twitter bio
JavaScript
108
star
2

monthly-venmo

A Python script to automate monthly Venmo requests
Python
66
star
3

mentored.dev

A gamified learning platform to help you become a web developer
TypeScript
60
star
4

use-streak

a streak counter to track your streak in days (similar to Duolingo)
TypeScript
35
star
5

telegram-bot-template

A Telegram bot template that uses telegraf.js + Vercel serverless functions
TypeScript
34
star
6

indie-university

Curated courses to help you grow as an indie hacker
33
star
7

web3-cheatsheet

A cheatsheet with all the best web3 resources
30
star
8

joeprevite.com

my digital garden 🌱
TypeScript
30
star
9

awesome-interactive-course-platforms

A curated list of awesome interactive course platforms, mostly teaching programming related things
25
star
10

react-ts-example

Example from React with TypeScript: Best Practices article
TypeScript
24
star
11

effective-typescript-notes

notes from "Effective TypeScript" by Dan Vanderkam
17
star
12

react-chrome-ext

A boilerplate for building Chrome Extensions with React
JavaScript
16
star
13

rusty-bunny

a tool that lets you write smart bookmarks
Rust
15
star
14

100-days-twilio-twitter

A simple app that lets you track your #100DaysOfCode progress with Twilio, Twitter and GitHub
JavaScript
13
star
15

react-ts-avatar

A basic <Avatar /> component inspired by GitHub
TypeScript
12
star
16

react-ts-vitest-template

A template with React, TypeScript, Vite, Vitest, React Testing Library
TypeScript
10
star
17

next-reason-relay-app

Reason
7
star
18

codemirror-line-numbers-relative

A CodeMirror (v6) extension for adding relative line numbers to your code editor
TypeScript
7
star
19

timezoner-extension

A simple extension to help you coordinate across timezones 🕑🌏
TypeScript
6
star
20

shareable-custom-hooks-react

All the code for my newest egghead course: Writing Shareable Custom Hooks in React
JavaScript
5
star
21

use-star-wars-quote

example custom hook
JavaScript
5
star
22

the-super-tiny-ts-compiler

super tiny ts compiler
TypeScript
5
star
23

typescript-concepts-and-examples

Understading TypeScript - Concepts and Examples
5
star
24

react-use-click-away

a custom React Effect for clicking away to close dropdowns
JavaScript
5
star
25

react-use-sw-quote

JavaScript
5
star
26

dotfiles

testing dotfiles
Lua
4
star
27

gatsby-tinacms-mdx

JavaScript
4
star
28

twilio-superclass

A resource for Twilio Superclass workshops 🎉😄
4
star
29

gatsby-netlify-firebase-basic

JavaScript
4
star
30

twilio-identify-unknown-numbers

a project to help you identify unknown phone numbers with Python, AWS Lambda, Twilio Lookup and SMS
Python
4
star
31

handle-origin-stories

origin stories behind GitHub handles
4
star
32

learning-roadmap

a repository to keep track of my roadmap to being a more knowledgeable developer
4
star
33

vsx-proxy

example express proxy to openvsx
TypeScript
3
star
34

create-express-ts

npx create-express-ts
JavaScript
3
star
35

joe-image

My Coder Dockerfile
Dockerfile
3
star
36

disney-subtitles-extension

Easily copy Disney subtitles with this extension
TypeScript
3
star
37

coder-templates

My templates for coder/coder
HCL
3
star
38

nest-graphql

playing around with nestjs & graphql
TypeScript
3
star
39

cowork-with-friends

making remote work less lonely
TypeScript
3
star
40

react-native-todo-list

A simple React Native todo list
JavaScript
2
star
41

react-use-star-wars-quote

JavaScript
2
star
42

jest-playwright-repro

Reproduction repo for Safari issue
TypeScript
2
star
43

future-js-gatsby

Slide deck for my talk at MagnoliaJS 2019
JavaScript
2
star
44

replicate-ts

App based off tutorial linked below
TypeScript
2
star
45

hello-world

test npm package: @jsjoeio/hello-world
TypeScript
2
star
46

streak-counter

a streak counter for the browser, inspired by Duolingo
TypeScript
2
star
47

code-server-railway-ipad

Shell
2
star
48

github-email-extension

A browser extension which gets a GitHub user's email from their commits
TypeScript
2
star
49

jp-courses

CLI for downloading my courses
TypeScript
2
star
50

vocab-miner

An app to help you mine new words
TypeScript
2
star
51

jsjoe.io

personal website
JavaScript
2
star
52

code-server-railway2

Dockerfile
1
star
53

add-ts-jest

npx add-ts-jest
TypeScript
1
star
54

learn-go-with-tests

my solutions and notes as I learn: https://quii.gitbook.io/learn-go-with-tests/
Go
1
star
55

astro-starter

rebuild of joeprevite.com with Astro
TypeScript
1
star
56

epic-nfts

JavaScript
1
star
57

task-management-frontend

frontend for the nestjs task management app (from Udemy course
JavaScript
1
star
58

portfolio-rebuild

A rebuild of my portfolio using Gatsby.js
JavaScript
1
star
59

joe_previte-SDK

TypeScript
1
star
60

cryptochain

TypeScript
1
star
61

playwright-test-repro

repo for playwright-test issue
TypeScript
1
star
62

powers-of-css-in-js

Slide deck for my talk at Byteconf JavaScript in March 2019
JavaScript
1
star
63

blog.jsjoe.io

personal blog
JavaScript
1
star
64

jsjoeio-SDK

1
star
65

learn-reason

Reason
1
star
66

github-actions-issue-label

a POC to run a GitHub action workflow when and issue label is added
1
star
67

guessing_game

Rust
1
star
68

speak-argentinian-spanish

speak argentinian spanish website
TypeScript
1
star
69

sentry-gatsby-blog

A demo of a Gatsby blog for Sentry
JavaScript
1
star
70

rustlings-answers

My answers to rustlings
Rust
1
star
71

vitejs-chat

Created with StackBlitz ⚡️
TypeScript
1
star
72

navigate-ts-oss

Vue
1
star
73

daily-ck-subscribers

TypeScript
1
star
74

text-me-riverflow

a small serverless function that sends daily texts with riverflow rates
JavaScript
1
star
75

gh-action-poc

JavaScript
1
star
76

adventofts

Advent of Code for the TypeScript community
TypeScript
1
star
77

desert-gql-apollo-link-rest

Slide deck for my lightning talk at Desert GraphQL on apollo-link-rest
JavaScript
1
star
78

docz-theme-example

CSS
1
star
79

fcc-random-quote-machine

A GraphQL API inspired by the freeCodeCamp Random Quote Machine project
JavaScript
1
star
80

react-use-chuck-norris

a custom React Hook that gives you a Chuck Norries joke
JavaScript
1
star
81

sr-fullstack-challenge

take home for smartrent
TypeScript
1
star
82

temperature_converter

Rust
1
star
83

task-queue

https://dev.to/sarbikbetal/simple-node-js-task-queue-with-bee-queue-and-redis-105b
TypeScript
1
star
84

exercism

Exercises from exercism
JavaScript
1
star
85

ts-init

a quick TypeScript template to get you started
1
star
86

simple-haskell-book

Quad project from book
Haskell
1
star
87

scrtch-prj

TypeScript
1
star
88

vite-issue-eslint

npm error Unable to resolve reference $eslint
CSS
1
star
89

vim

learning vim
Shell
1
star
90

twilio-todo-bot

A todo bot built in Node.js with Twilio API
JavaScript
1
star