Creating a great user experience is never an easy task. So most of the time we prefer to use existing UI libraries to reduce the time and increase productivity. In this article, we are going to learn about Chakra UI and also build a react application using Chakra UI components. We are going to use some of the components of Chakra UI in our application to see how easy it is to build a great UI.
In this article, I am going to cover the below points,
- What is Chakra UI?
- Create a React App
- Setup Chakra UI in React App
- Create a Navbar with Chakra UI Components
- Adding Dark mode functionality
What is Chakra UI?
According to documentation,
Chakra UI is a simple, modular and accessible component library that gives you all the building blocks you need to build your React applications.
Chakra UI is another great modular component library for React which uses Emotion and Styled System. It consists of a wide range of reusable React components that can make the life of a developer easy. Chakra UI has some design principals which you can check here.
Special things about Chakra UI
- Chakra UI has out of the box support for themes. You can customize themes very easily.
- It has out of the box support for Dark Mode.
- It is based on Styled Systems. It has the support of Emotion a CSS-in-JS library.
- Chakra UI consists of lots of components
Create a React App
Prerequisites
- We should have a basic knowledge of HTML and ReactJS.
- Visual Studio Code installed
- Node and NPM installed
Open a command prompt or your favorite terminal and type the below command to create a react app.
- npx create-react-app react-chakarui-app
- cd react-chakarui-app
To see how it look likes type the below command.
- npm start
and it will start the development server and navigate you to http://localhost:3000/
You can see the default landing page,

Setup Chakra UI in React App
Install Chakra UI in our new react app and its peer dependencies,
- npm install @chakra-ui/core @emotion/core @emotion/styled emotion-theming
Open our new app in Visual Studio code. Chakra UI has great theming support so open index.ts and import ThemeProvider and CSSReset component and apply at the root level. Chakra UI exports a CSSReset that'll remove browser default styles.
- import React from 'react';
- import ReactDOM from 'react-dom';
- import './index.css';
- import App from './App';
- import * as serviceWorker from './serviceWorker';
- import { theme, ThemeProvider, CSSReset } from "@chakra-ui/core";
- ReactDOM.render(
- <ThemeProvider theme={theme}>
- <CSSReset />
- <React.StrictMode>
- <App />
- </React.StrictMode>
- </ThemeProvider>,
- document.getElementById('root')
- );
- serviceWorker.unregister();
Create a Navbar with Chakra UI Components
Now create a new React component called Navbar.js. To create navbar we are using below Chakra UI components,
- Button
- Flex
- Box
- Text
Open Navbar.js file and add the below code,
- import React from "react";
- import {
- Box,
- Heading,
- Flex,
- Link
- } from "@chakra-ui/core";
- const MenuItems = ({ children }) => (
- <Link mt={{ base: 4, md: 0 }} mr={6} display="block">
- {children}
- </Link>
- );
- const Navbar = props => {
- return (
- <Flex
- as="nav"
- align="center"
- justify="space-between"
- wrap="wrap"
- padding="1.5rem"
- bg="gray.900"
- color="teal.300"
- borderBottom="1px solid black"
- {...props}
- >
- <Flex align="center" mr={5}>
- <Heading as="h1" size="lg" letterSpacing={"-.1rem"}>
- Chakra UI & React
- </Heading>
- </Flex>
- <Box
- display="flex"
- width="auto"
- alignItems="center"
- flexGrow={1}
- color="teal.300"
- >
- <MenuItems>Home</MenuItems>
- <MenuItems>Blogs</MenuItems>
- <MenuItems>About</MenuItems>
- <MenuItems>Contact</MenuItems>
- </Box>
- </Flex>
- );
- };
- export default Navbar;
Chakra UI provides the below layout utilities,
- Stack makes it easy to group elements together and apply a space between them.
-
Flex combines/wraps everything in a Flexbox container.
- Grid combines/wraps everything in a CSS Grid container.
- Box is simple a div element for receives style props.



Join the conversation! Your thoughts help the community grow.