14

I'm working with Chakra UI and i needed to customize the scrollbar style using the css pseudo element ::-webkit-scrollbar, but Chakra UI doesn't seen to have this pseudo element and a I don't know where I can style this specific component without creating a global css class.

Here is a sample of my code:

<Box
  overflowX="auto"
  maxW="100vw"
  h="100%"
  whiteSpace="nowrap"
  pb="17px"
  color="white"
  px="32px"
  // the ::-webkit-scrollbar property should goes here
>
  <!-- content -->
</Box>

4 Answers 4

34

Try css prop:

<Box
  overflowY="auto"
  css={{
    '&::-webkit-scrollbar': {
      width: '4px',
    },
    '&::-webkit-scrollbar-track': {
      width: '6px',
    },
    '&::-webkit-scrollbar-thumb': {
      background: scrollbarColor,
      borderRadius: '24px',
    },
  }}
>
Sign up to request clarification or add additional context in comments.

3 Comments

Do you know how to add ::-webkit-scrollbar-thumb:horizontal, cannot figure out what rules chakra is using internally for pseudo css.
This doesn't seem to work anymore.
Not sure if you still need this @Yunhai but for horizontal scroll bar you need to specify the height instead of the width.
8

Use Chakra sx prop here.

<Box
  overflowX="auto"
  maxW="100vw"
  h="100%"
  whiteSpace="nowrap"
  pb="17px"
  color="white"
  px="32px"
  sx={
     { 
    '::-webkit-scrollbar':{
           display:'none'
       }
    }
  }
>
  <!-- content -->
</Box>

To know more about Chakra sx prop, refer docs

Comments

2

It worked for me you can use overflow="scroll" and with this the prop sx={}

<Flex
    mt="20px"
    overflow="scroll"
    sx={{
      "::-webkit-scrollbar": {
        display: "none",
      },
    }}
  />

Comments

1

its not gonna work with just css you need to __css

<Box
  overflowY="auto"
  __css={{
        '&::-webkit-scrollbar': {
          w: '2',
        },
        '&::-webkit-scrollbar-track': {
          w: '6',
        },
        '&::-webkit-scrollbar-thumb': {
          borderRadius: '10',
          bg: `gray.100`,
        },
      }}
>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.