Search code examples
chakra-ui

How can I get the color hex value of Chakra UI theme color by its name?


Is there a function to get the hex value from a Chakra UI color?

Example:

getHexValue("gray.300") // "#CBD5E0"

Solution

  • Yes that function exist! Checkout useToken: https://chakra-ui.com/docs/styled-system/utility-hooks/use-token

    Note that's also easy to use the generated css variable : var(--chakra-colors-gray-300)