How to Create Modern Cards in Chakra UI & React JS ⚡️
Sometimes creating a great UI requires, not just time, but attention as well. Even when it comes to some cards, the attention to structure, spacings, color palette, and so on... is more than important.
These days, we can safely say that cards have become a design trend & staple across websites and mobile app UIs, we have examples from big companies like Revolut, Apple & Google that use interactive & modern cards on their websites and apps to give their customers and users a great experience in using their solutions!
So, when we start designing & developing a card we need to take into consideration some important aspects:
The card content should be very compact and intuitive, so we need to keep it in a single card structure.
The whole card should be very easy to read and use. This aspect makes the difference between a great and a bad UI & UX. So we need to pay attention to making it clean and airy (design tip: don't be afraid to use whitespace, use it as much as you can).
The card should have just the important elements that will expose the information, as I said above, we need to keep the card clean & airy. For example, a CTA card should contain a title, subtitle, maybe an image, and a CTA button that will make the action.
One more important aspect that defines the popularity of UI Cards is that they facilitate responsive UI design, they can easily scale down to any device resolution due to their squared shape that fits perfectly in any grid structure.
Let's get straight to our cards examples!
In today's example, we will make three simple cards updated to the latest UI trends. We've taken some design inspiration from Horizon UI React cards, you can see more awesome free react cards like this on their website.
Great, let's code them!
As you already saw, the React JS library that we are going to use today to build our beautiful cards is Chakra UI. Also, we are going to get some help from tools such as Chakra theme tools & React icons.
First of all, let's install Chakra UI & its above add-ons:
npm i @chakra-ui/react @chakra-ui/theme @chakra-ui/theme-tools react-icons
After this, we need to make a style.js file and type the following styles:
Great! In the components folder in /theme, we modified various Chakra UI components like <Button> or <Badge>, to use them we need to make a special folder with all styles files for each component we have (badge.js, button.js & breakpoints.js)!
Make a special file for the components below:
After we have modified general styles, it would also be helpful to set other breakpoints for responsive accuracy. Create a breakpoints.js file with the following code:
Good, now we need to make a new file called theme.js where we need toimport and add all styles to the theme we'll use in index.js. This will help define general styles for our awesome cards!
After this, in index.js, add the theme to the <ChakraProvider> component:
Amazing! Let's start coding the structure of our Chakra UI + React cards! ⚡️
All we need to do is to make a special file for each of them and paste the below code of them:
Chakra UI - Profile Card
Chakra UI - Teams Card
Chakra UI - Product Card
Great! Now in our App.js, we're going to import the card components that we created! The imports should look like this:
// Components Import
import Product from "./components/Product";
import Profile from "./components/Profile";
import Teams from "./components/Teams";
Conclusions & Resources ⭐️
In this article, we've been able to build complete and fully responsive cards using Chakra UI. I hope you found it helpful and interesting!
Here you will find the .zip file with today's project that contains the cards above!
Also, I really recommend to take a look and try Horizon UI, you will find more awesome cards like in this article, modern charts, and many other amazing UI elements. You will find them in a beautifully functional admin dashboard that is responsive to all devices! And is free & open-source!⚡️
Thanks for reading!
Frequently asked questions
Where can I find more Chakra UI templates?
Top websites with Chakra UI templates and themes you should use in 2022: