Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function colors bug #2919

merged 1 commit into from Feb 7, 2021


Copy link

@DylanVann DylanVann commented Nov 27, 2020

Describe the problem:

I am trying to use CSS variables for colors while keeping opacity functionality.

I believe the following config should work:

const color = (name) => ({ opacityVariable, opacityValue }) => {
  if (opacityValue !== undefined) {
    return `rgba(var(--twc-${name}), ${opacityValue})`
  if (opacityVariable !== undefined) {
    return `rgba(var(--twc-${name}), var(${opacityVariable}, 1))`
  return `rgb(var(--twc-${name}))`

const colorScale = (name) =>
  [50, 100, 200, 300, 400, 500, 600, 700, 800, 900].reduce(
    (acc, step) => ({
      [step]: color(`${name}-${step}`),

module.exports = {
  purge: ['./src/**/*.js'],
  theme: {
    extend: {
      colors: {
        foreground: color('foreground'),
        background: color('background'),
        accent: color('accent'),
        gray: colorScale('gray'),
  variants: {
    extend: {},
  plugins: [require('@tailwindcss/typography')],

This is based on

This currently results in an error: 'colors.gray.400' was found but does not resolve to a string.


This error occurs when trying to replace color: theme('colors.gray.400', #a1a1aa); in preflight.css.

The error is thrown inside validatePath because value is a function.

Link to a minimal reproduction:

Working Example

I've used patch-package to show how this should work:

Copy link

jaredhill4 commented Feb 5, 2021


Any chance this will be merged soon? The theme() function isn't working. 😢

@adamwathan adamwathan merged commit 33dcd44 into tailwindlabs:master Feb 7, 2021
2 checks passed
Copy link

adamwathan commented Feb 7, 2021

Thanks sorry for the delay!

This was referenced Mar 15, 2021
This was referenced Mar 18, 2021
adamwathan pushed a commit that referenced this pull request May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants