chakra-ui
⚡️ Simple, Modular & Accessible UI Components for your React Applications
Top Related Projects
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
A utility-first CSS framework for rapid UI development.
An enterprise-class UI design language and React UI library
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
👩🎤 CSS-in-JS library designed for high performance style composition
Quick Overview
Chakra UI is a simple, modular, and accessible component library for React applications. It provides a set of customizable and reusable components that help developers build user interfaces quickly and efficiently. Chakra UI is designed with a focus on accessibility, theming, and responsive design.
Pros
- Highly customizable and themeable components
- Excellent accessibility support out of the box
- Responsive design with built-in support for different screen sizes
- Well-documented with comprehensive guides and examples
Cons
- Learning curve for developers new to component-based UI libraries
- Some advanced customizations may require deeper knowledge of the library
- Limited set of pre-built components compared to some other UI libraries
- Performance impact when using many components in a large application
Code Examples
- Creating a simple button with Chakra UI:
import { Button } from '@chakra-ui/react'
function MyButton() {
return <Button colorScheme="blue">Click me</Button>
}
- Using Chakra UI's responsive styles:
import { Box } from '@chakra-ui/react'
function ResponsiveBox() {
return (
<Box
bg="red.500"
w={[300, 400, 500]}
h={['100px', '200px', '300px']}
>
Responsive Box
</Box>
)
}
- Creating a form with Chakra UI components:
import { VStack, Input, Button } from '@chakra-ui/react'
function SimpleForm() {
return (
<VStack spacing={4}>
<Input placeholder="Enter your name" />
<Input placeholder="Enter your email" type="email" />
<Button colorScheme="green" type="submit">
Submit
</Button>
</VStack>
)
}
Getting Started
To start using Chakra UI in your React project, follow these steps:
- Install Chakra UI and its peer dependencies:
npm i @chakra-ui/react @emotion/react @emotion/styled framer-motion
- Wrap your application with the ChakraProvider:
import { ChakraProvider } from '@chakra-ui/react'
function App() {
return (
<ChakraProvider>
{/* Your app components */}
</ChakraProvider>
)
}
- Start using Chakra UI components in your application:
import { Button, Box, Text } from '@chakra-ui/react'
function MyComponent() {
return (
<Box>
<Text fontSize="2xl">Welcome to Chakra UI</Text>
<Button colorScheme="teal">Get Started</Button>
</Box>
)
}
Competitor Comparisons
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
Pros of Material-UI
- More comprehensive component library with a wider range of pre-built components
- Stronger ecosystem with additional tools and extensions
- Longer history and larger community, potentially leading to better support and resources
Cons of Material-UI
- Steeper learning curve due to more complex API and customization options
- Heavier bundle size, which may impact performance in smaller projects
- Stricter adherence to Material Design guidelines, potentially limiting design flexibility
Code Comparison
Material-UI:
import { Button, ThemeProvider, createTheme } from '@mui/material';
const theme = createTheme();
function App() {
return (
<ThemeProvider theme={theme}>
<Button variant="contained">Click me</Button>
</ThemeProvider>
);
}
Chakra UI:
import { Button, ChakraProvider } from '@chakra-ui/react';
function App() {
return (
<ChakraProvider>
<Button colorScheme="blue">Click me</Button>
</ChakraProvider>
);
}
Both libraries offer component-based UI development with theming capabilities. Material-UI requires more setup with createTheme
and ThemeProvider
, while Chakra UI provides a simpler approach with ChakraProvider
. Material-UI uses specific prop names like variant
, whereas Chakra UI uses more intuitive props like colorScheme
.
A utility-first CSS framework for rapid UI development.
Pros of Tailwind CSS
- Highly customizable with a utility-first approach
- Smaller bundle size due to purging unused styles
- Rapid prototyping and development with pre-defined classes
Cons of Tailwind CSS
- Steeper learning curve for developers new to utility-first CSS
- Can lead to verbose HTML with multiple classes
- Less out-of-the-box component styling compared to Chakra UI
Code Comparison
Tailwind CSS:
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Button
</button>
Chakra UI:
<Button colorScheme="blue" size="md">
Button
</Button>
Summary
Tailwind CSS offers a utility-first approach with high customization and smaller bundle sizes, while Chakra UI provides a more component-based structure with pre-styled elements. Tailwind excels in rapid prototyping but may lead to verbose HTML, whereas Chakra UI offers a smoother learning curve with its component library. The choice between the two depends on project requirements and team preferences.
An enterprise-class UI design language and React UI library
Pros of Ant Design
- More comprehensive component library with a wider range of pre-built components
- Stronger enterprise-level design system with consistent patterns and guidelines
- Better support for complex data visualization and form handling
Cons of Ant Design
- Steeper learning curve due to its extensive API and configuration options
- Less flexibility in customization compared to Chakra UI's more modular approach
- Larger bundle size, which may impact initial load times for applications
Code Comparison
Ant Design button example:
import { Button } from 'antd';
const MyButton = () => (
<Button type="primary" size="large">
Click me
</Button>
);
Chakra UI button example:
import { Button } from '@chakra-ui/react';
const MyButton = () => (
<Button colorScheme="blue" size="lg">
Click me
</Button>
);
Both libraries offer similar component APIs, but Ant Design often requires more specific prop names (e.g., type="primary"
) while Chakra UI uses more generic props (e.g., colorScheme="blue"
). Chakra UI's approach allows for easier customization and theme integration, while Ant Design's specific props ensure consistency with its design system.
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
Pros of styled-components
- More flexible and powerful CSS-in-JS solution
- Better support for dynamic styling based on props
- Easier to create and manage complex component styles
Cons of styled-components
- Steeper learning curve for developers new to CSS-in-JS
- Potentially larger bundle size due to runtime styling
- Lack of pre-built components and design system
Code Comparison
styled-components:
const Button = styled.button`
background-color: ${props => props.primary ? 'blue' : 'white'};
color: ${props => props.primary ? 'white' : 'blue'};
padding: 10px 20px;
border: 2px solid blue;
`;
Chakra UI:
import { Button } from "@chakra-ui/react"
<Button colorScheme="blue" variant={primary ? "solid" : "outline"}>
Click me
</Button>
styled-components offers more flexibility in styling, allowing for complex CSS logic within the template literal. Chakra UI provides a more structured approach with pre-defined props and variants, making it easier to maintain consistency across the application but potentially limiting customization options.
👩🎤 CSS-in-JS library designed for high performance style composition
Pros of Emotion
- More flexible and lightweight, allowing for custom styling solutions
- Better performance due to smaller bundle size and optimized runtime
- Supports object styles, which can be easier for some developers to work with
Cons of Emotion
- Requires more setup and configuration compared to Chakra UI's out-of-the-box components
- Less opinionated, which may lead to inconsistent designs across teams
- Steeper learning curve for developers new to CSS-in-JS
Code Comparison
Emotion:
import { css } from '@emotion/react'
const style = css`
background-color: hotpink;
&:hover {
color: blue;
}
`
Chakra UI:
import { Box } from '@chakra-ui/react'
<Box
bg="hotpink"
_hover={{ color: 'blue' }}
>
Hello
</Box>
Emotion provides more granular control over styles, while Chakra UI offers a more declarative approach with pre-built components and utility props. Chakra UI is built on top of Emotion, combining its power with a comprehensive component library and design system.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Build Accessible React Apps with Speed â¡ï¸
Chakra UI is a comprehensive library of accessible, reusable, and composable React components that streamlines the development of modern web applications and websites. The library offers a diverse range of components that can be easily combined to build complex user interfaces while adhering to accessibility best practices.
Table of contents
- ð Documentation
- ð Features
- ð¦ Installation
- ð» Usage
- ð CodeSandbox Templates
- ð
create-react-app
Templates - ð Contributing
- ð Support
- ð Testimonials
- ð Awards and Mentions
- ⨠Contributors
- âï¸ License
Documentation
It's the https://chakra-ui.com website for the latest version of Chakra UI. For older versions head over here
Features
- Ease of Styling: Chakra UI contains a set of layout components like
Box
andStack
that make it easy to style your components by passing props. Learn more - Flexible & composable: Chakra UI components are built on top of a React UI Primitive for endless composability.
- Accessible. Chakra UI components follow the WAI-ARIA guidelines specifications
and have the right
aria-*
attributes. - Dark Mode ð: Most components in Chakra UI are dark mode compatible.
Installation
To use Chakra UI components, all you need to do is install the
@chakra-ui/react
package and its peer dependencies:
# with Yarn
$ yarn add @chakra-ui/react @emotion/react
# with npm
$ npm i @chakra-ui/react @emotion/react
# with pnpm
$ pnpm add @chakra-ui/react @emotion/react
# with Bun
$ bun add @chakra-ui/react @emotion/react
Usage
To start using the components, please follow these steps:
- Wrap your application with the
ChakraProvider
provided by @chakra-ui/react.
import { ChakraProvider, defaultSystem } from "@chakra-ui/react"
// Do this at the root of your application
function App({ children }) {
return <ChakraProvider value={defaultSystem}>{children}</ChakraProvider>
}
Optionally, you can wrap your application with the ColorModeProvider
so you
can toggle between light and dark mode within your app.
- Now you can start using components like so!:
import { Button } from "@chakra-ui/react"
function Example() {
return <Button>I just consumed some â¡ï¸Chakra!</Button>
}
More guides on how to get started are available here
CodeSandbox Templates
- JavaScript Starter: https://codesandbox.io/s/chakra-ui-javascript-lzzg9
- TypeScript Starter: https://codesandbox.io/s/chakra-ui-typescript-pomi8
- NextJS TypeScript Starter: https://codesandbox.io/s/chakra-ui-next-js-typescript-kxvyr
create-react-app
Templates
Check out our guide for
information on how to use our official create-react-app
templates.
Contributing
Feel like contributing? That's awesome! We have a contributing guide to help guide you.
Our docsite lives in a separate repo. If you're interested in contributing to the documentation, check out the docsite contribution guide.
Support Chakra UI
Organizations
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
Individuals
By donating $5 or more you can support the ongoing development of this project. We'll appreciate some support. Thank you to all our supporters! ð [Contribute]
Testimonials
People throw React component libraries and design systems at me regularly. This might be the best one I've seen. The APIs are simple but composable and the accessibility on the couple components I looked is complete.
Great work @thesegunadebayo, really inspiring work. â Ryan Florence
Awesome new open-source component library from @thesegunadebayo. Really impressive stuff! â Colm Tuite
This is incredible work. Amazing job Segun! â Lee Robinson
Chakra UI is glorious! I love the consistent use of focus styling and the subtle animation â Guillermo â²
Awards and Mentions
We've been extremely humbled to receive awards and mentions from the community for all the innovation and reach Chakra UI brings to the JavaScript ecosystem.
Solution Worth PursuingTechnology Radar (2020â2021) |
|
The Most Impactful Contribution to the communityOpen Source Awards (2020) |
Contributors
Thanks goes to these wonderful people
(emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Testing supported by
License
MIT © Segun Adebayo
Top Related Projects
Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
A utility-first CSS framework for rapid UI development.
An enterprise-class UI design language and React UI library
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
👩🎤 CSS-in-JS library designed for high performance style composition
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot