Emotion – @emotion/css (original) (raw)

The @emotion/css package is framework agnostic and the simplest way to use Emotion.

Table of Contents

Quick Start

Get up and running with a single import.

API

css

The css function accepts styles as a template literal, object, or array of objects and returns a class name. It is the foundation of emotion.

String Styles

Object Styles

Array of Object Styles

Global Styles

injectGlobal injects styles into the global scope and is useful for applications such as css resets or font faces.

Animation Keyframes

keyframes generates a unique animation name that can be used to animate elements with CSS animations.

String Styles

Object Styles

cx

cx is emotion's version of the popular classnames library. The key advantage of cx is that it detects emotion generated class names ensuring styles are overwritten in the correct order. Emotion generated styles are applied from left to right. Subsequent styles overwrite property values of previous styles.

Combining class names

Conditional class names

Using class names from other sources

Custom Instances

With @emotion/css/create-instance, you can provide custom options to Emotion's cache.

The main @emotion/css entrypoint can be thought of as a call to @emotion/css/create-instance with sensible defaults for most applications.

Upside

Downside

Primary use cases

Multiple instances in a single app example

Options

createEmotion accepts the same options as createCache from @emotion/cache.