Skip to content

Theme

Customizing the default theme for your project.

The theme section of your windi.config.js or windi.config.ts file is where you define your project’s color palette, type scale, fonts, breakpoints, border radius values, and more.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  screens: {
    sm: "480px",
    md: "768px",
    lg: "976px",
    xl: "1440px",
  },
  colors: {
    blue: "#1fb6ff",
    purple: "#7e5bef",
    pink: "#ff49db",
    orange: "#ff7849",
    green: "#13ce66",
    yellow: "#ffc82c",
    grayDark: "#273444",
    gray: "#8492a6",
    grayLight: "#d3dce6",
  },
  fontFamily: {
    sans: ["Graphik", "sans-serif"],
    serif: ["Merriweather", "serif"],
  },
  extend: {
    spacing: {
      128: "32rem",
      144: "36rem",
    },
    borderRadius: {
      xl: {
        4: "2rem",
      },
    },
  },
});

Theme structure

The theme object contains keys for screens, colors, and spacing, as well as a key for each customizable utilities.

See the theme configuration reference or the default theme config for a complete list of theme options.

TIP

If you have experience with windicss/tailwindcss, you should pay attention to the differences, the way how configuration works in windijs is completely different, for more info please refer to this post.

Screens

The screens key allows you to customize the responsive breakpoints in your project.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    screens: {
      sm: "640px", // => @media (min-width: 640px) { ... }
      md: "768px", // => @media (min-width: 768px) { ... }
      lg: "1024px", // => @media (min-width: 1024px) { ... }
      xl: "1280px", // => @media (min-width: 1280px) { ... }
      xxl: "1536px", // => @media (min-width: 1536px) { ... }
    },
  },
});

Overriding a single screen

To override a single screen size (like lg), add your custom screens value under the theme.extend key:

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    extend: {
      screens: {
        lg: "992px", // => @media (min-width: 992px) { ... }
      },
    },
  },
});

Adding new breakpoints

You can also use the extend key to add new breakpoints.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    extend: {
      screens: {
        tiny: "345px", // => @media (min-width: 345px) { ... }
        big: "1600px", // => @media (min-width: 1600px) { ... }
      },
    },
  },
});

Custom media queries

By default, Windi JS will use mobile first mode, which means generating media query like @media (min-width: ...).

If you want to use a custom media query, such as desktop first mode, it's very easy, you need to use the variants key to achieve it. The new variants we define with the variants key will replace the previous variants generated by theme.screens.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  variants: {
    xxl: "@media (max-width: 1535px)",
    xl: "@media (max-width: 1279px)",
    lg: "@media (max-width: 1023px)",
    md: "@media (max-width: 767px)",
    sm: "@media (max-width: 639px)",
  },
});

TIP

You must think that we can define a function to do this, Windi JS currently does not provide this helper, but you can easily do it yourself.

js
import { defineConfig } from "windijs";

const desktopVariants = screens => Object.fromEntries(Object.entries(screens).map(([k, v]) => [k, `@media (max-width: ${v})`]));

export default defineConfig({
  variants: {
    ...desktopVariants({
      xxl: "1535px",
      xl: "1279px",
      lg: "1023px",
      md: "767px",
      sm: "639px",
    }),
  },
});

Or if you want your breakpoints to specify both a min-width and a max-width.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  variants: {
    sm: "@media (min-width: 640px and max-width: 767px)",
    md: "@media (min-width: 768px and max-width: 1023px)",
    lg: "@media (min-width: 1024px and max-width: 1279px)",
    xl: "@media (min-width: 1280px and max-width: 1535px)",
    xxl: "@media (min-width: 1536px)",
  },
});

Custom variant is a very powerful feature, please refer to the Custom Variant Section for more information.

Colors

The colors key allows you to customize the global color palette for your project.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    colors: {
      transparent: "transparent",
      black: "#000",
      white: "#fff",
      gray: {
        100: "#f7fafc",
        // ...
        900: "#1a202c",
      },
      // ...
    },
  },
});

By default, these colors used by all color-related utilities, like bg, border, text, and others.

Using custom colors

If you’d like to completely replace the default color palette with your own custom colors, add your colors directly under the theme.colors section of your configuration file:

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    colors: {
      transparent: "transparent",
      current: "currentColor",
      white: "#ffffff",
      purple: "#3f3cbb",
      midnight: "#121063",
      metal: "#565584",
      silver: "#ecebff",
      bubbleGum: "#ff77e9",
      bermuda: "#78dcca",
      tahiti: {
        DEFAULT: "#06b6d4",
        100: "#cffafe",
        200: "#a5f3fc",
        300: "#67e8f9",
        400: "#22d3ee",
        500: "#06b6d4",
        600: "#0891b2",
        700: "#0e7490",
        800: "#155e75",
        900: "#164e63",
      },
      rgbColor: "rgb(22, 22, 22)",
      rgbaColor: "rgba(22, 22, 22, 0.5)",
      hslColor: "hsl(10, 10%, 20%)",
      hwbColor: "hwb(10 10% 20% / 0.2)",
      withVariable: "rgb(var(--color-secondary))",
    },
  },
});

You can also extend the default colors.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    extend: {
      colors: {
        brown: {
          50: "#fdf8f6",
          100: "#f2e8e5",
          200: "#eaddd7",
          300: "#e0cec7",
          400: "#d2bab0",
          500: "#bfa094",
          600: "#a18072",
          700: "#977669",
          800: "#846358",
          900: "#43302b",
        },
      },
    },
  },
});

Using built-in colors

Windi JS includes a range of popular framework colors, they are from (apple/bootstrap/bulma/material/tailwind/web/windi), you can choose the best for yourself. And also don't forget to say thanks to all these frameworks and their developers.

For example, if you want to use material colors.

windi.config.js
js
import { baseColors, materialColors, defineConfig } from "windijs";

export default defineConfig({
  theme: {
    colors: {
      ...baseColors, // including inherit, current, transparent, black, white
      ...materialColors, // iOSColor, macOSColors, watchOSColors, bootstrapColors, bulmaColors, tailwindColors, webColors, windiColors
    },
  },
});

You can also combine different colors from variant frameworks.

windi.config.js
js
import { baseColors, bootstrapPink, bulmaRed, materialOrange, tailwindCyan, windiDark, windiLight, defineConfig } from "windijs";

export default defineConfig({
  theme: {
    colors: {
      ...baseColors,
      pink: bootstrapPink,
      red: bulmaRed,
      orange: materialOrange,
      green: webGreen,
      cyan: tailwindCyan,
      dark: windiDark,
      light: windiLight,
    },
  },
});

All built-in colors defined in the package @windijs/colors package. Please refer to the colors API documentation for more details.

Generating colors

Windi JS has very powerful color processing helpers built in, which allowing you to quickly generate your own color patterns, convert bright colors to dark colors, and other colors processing methods.

js
import { Color, getDarkColor, getLightColor } from "windijs";

const red = new Color("#ff0000");
red.lightenSet(5).map(i => i.hex); // ["#f00", "#f33", "#f66", "#f99", "#fcc"]
red.darkenSet(5).map(i => i.hex); // ["#f00", "#c00", "#900", "#600", "#300"]

getLightColor(Color.hex("#485fc7")).hex; // "#eff1fa"
getDarkColor(Color.hex("#485fc7")).hex; // "#384fb8"

Color.hex("#c69").saturate(20).hex; // "#e05299"
Color.hex("#d2e1dd").scale({ lightness: -10, saturation: 10 }).hex; // "#b1d3ca"

// more...

All built-in helpers defined in the package @windijs/helpers package. Please refer to the helpers API documentation for more details.

Spacing

The spacing key allows you to customize the global spacing and sizing scale for your project.

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
    theme: {
        spacing: {
            0: '0',
            1: '0.25rem',
            2: '0.5rem',
            3: '0.75rem',
            3.5: '0.875',
            4': '24px',
            5: '32px',
            6: '48px',
        }
    }
})

By default, these values inherited by the padding, margin, width, height, maxHeight, gap, inset, space, translate utilities...

Other Options

The rest of the theme options used to configure which values are available for each individual utility.

For example, the borderRadius key lets you customize which border radius utilities will generated:

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    borderRadius: {
      none: "0",
      sm: ".125rem",
      DEFAULT: ".25rem",
      lg: ".5rem",
      full: "9999px",
    },
  },
});

The keys determine how you use these utilities, and the values determine the value of the actual CSS declaration.

The example borderRadius configuration can used like this,

js
[rounded.none, rounded.sm, rounded, rounded.lg, rounded.full];

and they would generate the following CSS classes:

css
/* rounded.none */
.a {
  border-radius: 0;
}
/* rounded.sm */
.b {
  border-radius: 0.125rem;
}
/* rounded */
.c {
  border-radius: 0.25rem;
}
/* rounded.lg */
.d {
  border-radius: 0.5rem;
}
/* rounded.full */
.e {
  border-radius: 9999px;
}

You’ll notice that using a key of DEFAULT in the theme configuration created the class rounded with no suffix. This is a common convention in Windi and supported by all utilities.

To learn more about customizing a specific utility, visit the documentation for that utility.

For a complete reference of available theme properties and their default values, see the default theme configuration.

Theme customzation

Out of the box, your project will use the values from the default theme configuration. If you would like to customize the default theme, you have a few different options depending on your goals. ​

Extending the default theme

If you’d like to preserve the default values for a theme option but also add new values, add your extensions under the extend key in the theme section of your configuration file.

For example, if you wanted to add an extra breakpoint but preserve the existing ones, you could extend the screens property:

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
  theme: {
    extend: {
      screens: {
        big: "1600px",
      },
    },
  },
});

Overriding the default theme

To override an option in the default theme, add your overrides directly under the theme section of your windi.config.js:

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
    theme: {
        opacity: {
            0: "0",
            20: "0.2",
            40: "0.4",
            60: "0.6",
            80: "0.8",
            100: "1",
        },
    },
};

This will completely replace Windi's default configuration for that key, so in the example above none of the default opacity utilities would generated.

Any keys you do not provide will inherited from the default theme, so in the above example, the default theme configuration for things like colors, spacing, borderRadius, etc. would preserved.

You can of course both override some parts of the default theme and extend other parts of the default theme within the same configuration:

windi.config.js
js
import { defineConfig } from "windijs";

export default defineConfig({
    theme: {
        opacity: {
            0: "0",
            20: "0.2",
            40: "0.4",
            60: "0.6",
            80: "0.8",
            100: "1",
        },
        extend: {
            screens: {
                big: '1600px',
            }
        }
    },
};

Referencing other values

If you need to reference another value in your theme, you need to extract them out. Currently, Windi JS does not support theme function, you can check this article to understand why.

For example, you could generate backgroundSize utilities for every value in your spacing scale:

windi.config.js
js
import { defineConfig } from "windijs";

const spacing = {
    0: '0',
    1: '0.25rem',
    2: '0.5rem',
    3: '0.75rem',
    3.5: '0.875',
    4': '24px',
    5: '32px',
    6: '48px',
}

export default defineConfig({
    theme: {
        spacing,
        backgroundSize: {
            auto: 'auto',
            cover: 'cover',
            contain: 'contain',
            ...spacing
        }
    }
})

Referencing the default theme

If you’d like to reference a value in the default theme for any reason, you can import it directly. Each of the default theme is a separate object, such as borderRadiusConfig, fontFamilyConfig, ...

One example of where this is useful is if you’d like to add a font family to one of Windi’s default font stacks:

windi.config.js
js
import { defineConfig, fontFamilyConfig } from "windijs";

export default defineConfig({
  theme: {
    extend: {
      fontFamily: {
        sans: ["Lato", ...fontFamilyConfig.sans],
      },
    },
  },
});

Config reference

Except for screens, colors, and spacing, all the keys in the theme object map to one of Windi's utilities. Since many utilities are responsible for CSS properties that only accept a static set of values (like float for example), note that not every plugin has a corresponding key in the theme object.

All these keys are also available under the theme.extend key to enable extending the default theme.

KeyDescription
screensYour project's responsive breakpoints
colorsYour project's color palette
columnsValues for the columns property
spacingYour project's spacing scale
animationValues for the animation property
aspectRatioValues for the aspect-ratio property
backdropBlurValues for the backdropBlur utility
backdropBrightnessValues for the backdropBrightness utility
backdropContrastValues for the backdropContrast utility
backdropGrayscaleValues for the backdropGrayscale utility
backdropHueRotateValues for the backdropHueRotate utility
backdropInvertValues for the backdropInvert utility
backdropOpacityValues for the backdropOpacity utility
backdropSaturateValues for the backdropSaturate utility
backdropSepiaValues for the backdropSepia utility
backgroundColorValues for the background-color property
backgroundImageValues for the background-image property
backgroundOpacityValues for the background-opacity property
backgroundPositionValues for the background-position property
backgroundSizeValues for the background-size property
blurValues for the blur utility
brightnessValues for the brightness utility
borderColorValues for the border-color property
borderOpacityValues for the borderOpacity utility
borderRadiusValues for the border-radius property
borderSpacingValues for the border-spacing property
borderWidthValues for the borderWidth utility
boxShadowValues for the box-shadow property
boxShadowColorValues for the boxShadowColor utility
caretColorValues for the caret-color property
accentColorValues for the accent-color property
contrastValues for the contrast utility
containerConfiguration for the container utility
contentValues for the content property
cursorValues for the cursor property
divideColorValues for the divideColor utility
divideOpacityValues for the divideOpacity utility
divideWidthValues for the divideWidth utility
dropShadowValues for the dropShadow utility
fillValues for the fill utility
grayscaleValues for the grayscale utility
hueRotateValues for the hueRotate utility
invertValues for the invert utility
flexValues for the flex property
flexBasisValues for the flex-basis property
flexGrowValues for the flex-grow property
flexShrinkValues for the flex-shrink property
fontFamilyValues for the font-family property
fontSizeValues for the font-size property
fontWeightValues for the font-weight property
gapValues for the gap property
gradientColorStopsValues for the gradientColorStops utility
gridAutoColumnsValues for the grid-auto-columns property
gridAutoRowsValues for the grid-auto-rows property
gridColumnValues for the grid-column property
gridColumnEndValues for the grid-column-end property
gridColumnStartValues for the grid-column-start property
gridRowValues for the grid-row property
gridRowStartValues for the grid-row-start property
gridRowEndValues for the grid-row-end property
gridTemplateColumnsValues for the grid-template-columns property
gridTemplateRowsValues for the grid-template-rows property
heightValues for the height property
insetValues for the `top, right, bottom, and left properties
keyframes Keyframevalues used in the animation utility
letterSpacingValues for the letter-spacing property
lineHeightValues for the line-height property
listStyleTypeValues for the list-style-type property
marginValues for the margin property
maxHeightValues for the max-height property
maxWidthValues for the max-width property
minHeightValues for the min-height property
minWidthValues for the min-width property
objectPositionValues for the object-position property
opacityValues for the opacity property
orderValues for the order property
paddingValues for the padding property
placeholderColorValues for the placeholderColor utility
placeholderOpacityValues for the placeholderOpacity utility
outlineColorValues for the outline-color property
outlineOffsetValues for the outline-offset property
outlineWidthValues for the outline-width property
ringColorValues for the ringColor utility
ringOffsetColorValues for the ringOffsetColor utility
ringOffsetWidthValues for the ringOffsetWidth utility
ringOpacityValues for the ringOpacity utility
ringWidthValues for the ringWidth utility
rotateValues for the rotate utility
saturateValues for the saturate utility
scaleValues for the scale utility
sepiaValues for the sepia utility
skewValues for the skew utility
spaceValues for the space utility
strokeValues for the stroke property
strokeWidthValues for the stroke-width property
textColorValues for the text-color property
textDecorationColorValues for the text-decoration-color property
textDecorationThicknessValues for the text-decoration-thickness property
textUnderlineOffsetValues for the text-underline-offset property
textIndentValues for the text-indent property
textOpacityValues for the textOpacity utility
transformOriginValues for the transform-origin property
transitionDelayValues for the transition-delay property
transitionDurationValues for the transition-duration property
transitionPropertyValues for the transition-property property
transitionTimingFunctionValues for the transition-timing-function property
translateValues for the translate utility
widthValues for the width property
willChangeValues for the will-change property
zIndexValues for the z-index property

All built-in theme configs defined in the package @windijs/config package. Please refer to the config API documentation for more details.

Released under the MIT License.