Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

platform-colors Logo


Generate platform native colors for iOS, Android & Web

Build Status NPM Package License Developed at Klarna

Using colors from the underlying platform primitives is powerful, but maintaining it when targeting multiple platforms is quite cumbersome. With this CLI you can generate colors and entrypoint for both iOS, Android, and Web with ease.

Under the hood we are using PlatformColor on React Native and CSS custom properties on web.


Easy to use

Type/JavaScript constants are generated automatically – using it with React/Native is as simple as importing the color name.


Using platform colors enables you to change from light/dark mode instantly and without any additional rerenders.


By utilizing the underlying platforms high contrast colors are supported out of the box.


npx @klarna/platform-colors

The first time you run the command it will prompt you which platforms you want to generate files for which will create a file with the following format:

// platform-colors.config.js
module.exports = {
  colors: {
    background: {
      light: '#ffffff',
      dark: '#000000',
    accent: 'pink',
  javascript: {
    typescript: true,
    outputDirectory: 'src/colors/',
  ios: {
    outputDirectory: 'ios/YourApp/Images.xcassets/',
  android: {
    outputDirectory: 'android/app/src/main/res/',
  css: {
    outputDirectory: 'static/css/',

NOTE: You need to re-run the command after each change to the config to update the generated files.

Now go ahead and inspect your android, ios and web folders. You should have your color definitions on each platform.



An object where the key is the color name, and the value is either a string or an object containing light and optionally highContrastLight, dark & highContrastDark properties.


  colors: {
    contrasted: {
      light: '#ccc',
      highContrastLight: '#fff',
      dark: '#333',
      highContrastDark: '#000',


An object containing outputDirectory which should be an .xcassets directory.


  ios: {
    outputDirectory: 'ios/YourProject/Assets.xcassets/'


An object containing outputDirectory which should be an Android res directory.


  android: {
    outputDirectory: 'android/app/src/main/res/'


An object containing outputDirectory and filename which should be a directory where you store CSS files and if you want to change the default filename from colors.css.


  css: {
    filename: 'example.css',
    outputDirectory: 'static/css/'


An object containing outputDirectory which should be a directory where you store your Type/JavaScript files and typescript which is set to true if you want the output in TypeScript.


  "javascript": {
    "typescript": true,
    "outputDirectory": "src/colors/"

Getting hex value from dynamic color

Note: You must first make sure you've added @klarna/platform-colors as a dependency and recompiled the app.

import { PlatformColor } from 'react-native';
import { resolveColorSync } from '@klarna/platform-colors';

const hexColor = resolveColorSync(PlatformColor('colorName'));


We prefix all colors with rnpc_ by default, you can override that with this option.


  prefix: 'custom_',
  // colors...

Development Setup

Install dependencies and make sure the tests are working

yarn install
yarn test

Example App

There's an example React Native App available to test under the examples app.

cd examples/ColorViewerApp
pod install --project-directory=ios

Running it either on ios or android by:

yarn ios


yarn android


Screenshot in dark mode Screenshot in dark mode

How to contribute

See our changelog.


Update version in package.json and merge to master. This will publish the package to NPM, create a draft release on GitHub and a version tag. Edit the release with additional information and publish it.

Copyright © 2021 Klarna Bank AB

For license details, see the LICENSE file in the root of this project.