theme-ui Documentation

Build consistent, themeable React apps based on constraint-based design principles

5,394 stars TypeScript TypeScript 1 file Β· ~6,253 tokens #color#design#design-system#design-tokens#emotion#layout#mdx#react
RAW Doc

Theme UI

 


Theme UI is a library for creating themeable user interfaces based on constraint-based
design principles. Build custom component libraries, design systems, web applications,
Gatsby themes, and more with a flexible API for best-in-class developer ergonomics.

stable docs: https://theme-ui.com
develop (prerelease) docs: https://dev.theme-ui.com


Built for design systems, white-labels, themes, and other applications where
customizing colors, typography, and layout are treated as first-class citizens
and based on a standard Theme Specification, Theme UI is intended to work in
a variety of applications, libraries, and other UI components. Colors,
typography, and layout styles derived from customizable theme-based design
scales help you build UI rooted in constraint-based design principles.

  • The next evolution of Styled System
  • From the creators of utility-based, atomic CSS methodologies
  • Theme-based styling with the sx prop
  • Compatible with virtually any UI component library
  • Works with existing Styled System components
  • Quick mobile-first responsive styles
  • Built-in support for dark modes
  • Primitive page layout components
  • Completely customizable with robust theming
  • Built with a standard Theme Specification for interoperability
  • Built with Emotion for scoped styles
  • Plugin for use in Gatsby sites and themes
  • Style MDX content with a simple, expressive API
  • Works with Typography.js themes

Getting Started

sh
npm install theme-ui @emotion/react

If you don't need color modes or components you can install
@theme-ui/core
.

Any styles in your app can reference values from the global theme object. To
provide the theme in context, wrap your application with the ThemeUIProvider
component and pass in a custom theme object.

jsx
// basic usage
import { ThemeUIProvider } from 'theme-ui'
import theme from './theme'

export default (props) => (
  {props.children}
)

The theme object follows the System UI
Theme Specification, which lets you define
custom color palettes, typographic scales, fonts, and more. Read more about
theming.

js
// example theme.js
export default {
  fonts: {
    body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif',
    heading: '"Avenir Next", sans-serif',
    monospace: 'Menlo, monospace',
  },
  colors: {
    text: '#000',
    background: '#fff',
    primary: '#33e',
  },
}

`sx` prop

The sx prop works similarly to Emotion's css prop, accepting style objects
to add CSS directly to an element in JSX, but includes extra theme-aware
functionality. Using the sx prop for styles means that certain properties can
reference values defined in your theme object. This is intended to make
keeping styles consistent throughout your app the easy thing to do.

The sx prop only works in modules that have defined a custom pragma at the top
of the file, which replaces the default React JSX functions. This means you can
control which modules in your application opt into this feature without the need
for a Babel plugin or additional configuration.

jsx
/** @jsxImportSource theme-ui */

export default (props) => (
  
    Hello
  
)

Read more about
how the custom pragma works.

Responsive styles

The sx prop also supports using arrays as values to change properties
responsively with a mobile-first approach. This API originated in Styled
System
and is intended as
a terser syntax for applying responsive styles
across a singular dimension.

jsx
/** @jsxImportSource theme-ui */

export default (props) => (
  
)

Documentation

MIT License

Contributors ✨

Thanks goes to these wonderful people
(emoji key):

Brent JacksonπŸ€” πŸ’» 🎨 πŸ“– πŸ’‘ ⚠️ πŸ‘€ Piotr Monwid-OlechnowiczπŸ’» πŸ“– ⚠️ πŸ‘€ πŸ’‘ Dany CastilloπŸ’» πŸ“– πŸ’‘ ⚠️ Jordan OverbyeπŸ’» πŸ’‘ ⚠️ Lachlan CampbellπŸ’» πŸ’‘ ⚠️ πŸ‘€ πŸ“– πŸ’¬ John OtanderπŸ’» πŸ‘€ πŸ“– ⚠️ πŸ€” David BurlesπŸ’» πŸ‘€ ⚠️ πŸ“– Max StoiberπŸ’» πŸ‘€ ⚠️ πŸ’‘
Atanas StoyanovπŸ’» πŸ’¬ ⚠️ πŸ› πŸ“– LennartπŸ’» πŸ› πŸ“– πŸ’‘ Aleksandra SikoraπŸ’» LBπŸ’» ⚠️ Francis ChampagneπŸ’» πŸ› ⚠️ πŸ“– Alex PageπŸ’» πŸ“– Adam SchayπŸ’» AlexπŸ’» πŸ“–
James EdmondsπŸ’» πŸ“– Florent SCHILDKNECHTπŸ’» πŸ“– Cole BemisπŸ’» ⚠️ πŸ“– John LeteyπŸ“– Yuraima EstevezπŸ’» Allan PopeπŸ’» πŸ“– Emmanuel PilandeπŸ’» Justin HallπŸ’»
MarekπŸ’» πŸ› BjΓΆrn CleesπŸ“– πŸ’» Iurii KucherovπŸ“– Joe StrouthπŸ’» πŸ› Stewart EverettπŸ’» Travis ArnoldπŸ’» πŸ“– Ivo ReisπŸ’» Benedikt RΓΆtschπŸ› πŸ“–
Jacob CofmanπŸ“– John LeteyπŸ“– Lawrence GossetπŸ“– Markos KonstantopoulosπŸ“– Robin MilletteπŸ’» Rodney FolzπŸ’» Rodrigo PomboπŸ’» ⚠️ πŸ“– Scott SilviπŸ“–
Shawn AllenπŸ“– Tomas CarneckyπŸ’» πŸ› John PolacekπŸ’» πŸ› mackieπŸ’» Aaron AdamsπŸ’» πŸ› πŸ“– AmberleyπŸ’» Andreea NΔƒstaseπŸ“– Anson Low Z.FπŸ› πŸ“–
Bernhard GschwantnerπŸ’» Bhanu Prakash KorthiwadaπŸ“– Bruno LemosπŸ“– Bryce FischerπŸ’» Dan WoodπŸ“– DebsπŸ“– Edward O'ReillyπŸ’» πŸ› Eric SchaeferπŸ’»
Felix GreenπŸ“– Gerhard BliedungπŸ’» πŸ› Guayo MenaπŸ’‘ Guilherme LimaπŸ“– Herb CaudillπŸ“– Jacob BoldaπŸ’» πŸ› Jason LengstorfπŸ› πŸ“– Jason Rundell (he/him)πŸ’‘
Joe RaceπŸ“– Kanstantsin KlimashevichπŸ“– EkaπŸ“– πŸ› Keir WilliamsπŸ“– KristΓ³f PoduszlΓ³πŸ’» πŸ› πŸ€” Kyle GillπŸ“– Kyle HolmbergπŸ“– Jay LaicheπŸ’»
Marc WiestπŸ’» Matheus TeixeiraπŸ’» matt-cratebindπŸ“– Matt ZabriskieπŸ’» Maxime KhoyπŸ’» Michael FriedmanπŸ“– Michael Zetterberg fd. LopezπŸ’» Nathan KnowlerπŸ’»
Neeraj LagwankarπŸ“– Owen YoungπŸ’» Patrick ArminioπŸ’» πŸ› Pedro DuarteπŸ’» Ray ClananπŸ’» Rich WerdenπŸ“– Rob PhoenixπŸ“– πŸ› Robert MoggachπŸ’» πŸ›
Anand NarayanπŸ’» πŸ› Sam PoderπŸ“– Sam RoseπŸ“– SohrabπŸ’» Spencer RinehartπŸ’» SteveπŸ“– Steve BartonπŸ“– Tim ReynoldsπŸ’» πŸ›
VinΓ­cius LemesπŸ“– Yihwan KimπŸ’» πŸ› Yuriy BurychkaπŸ“– ZolwiastylπŸ’» Amrish KushwahaπŸ’» Joe BellπŸ’» πŸ› kenny-loveholidaysπŸ’» β¦‡β¦€βˆ™Λ‡βˆŽΛ‡βˆ™β¦€β¦ˆπŸ’» πŸ›
navsghπŸ“– Shane O'NeillπŸ“– ζ±ͺη£ŠπŸ’» πŸ› Carolin MaisenbacherπŸ’» πŸ“– ⚠️ Alex ChanπŸ“– πŸ’‘ ⚠️ πŸ’» KennyπŸ’» Jordie BodlayπŸ“– Matt GleichπŸ“–
William PeiπŸ“– πŸ’‘ πŸ’» ⚠️ Greg PooleπŸ“– AkashπŸ“– πŸ’» Cannon LockπŸ“– kamatteπŸ“– πŸ’» Simen A. W. OlsenπŸ“– πŸ’‘ ⚠️ πŸ’» Wahid RahimπŸ“– πŸ’‘ πŸ’» Justin CooperπŸ“–
CJπŸ“– πŸ’» Sam MarxzπŸ“–

This project follows the
all-contributors
specification. Contributions of any kind welcome!