DEV Community

Cover image for How can you create dashboard stats card using Tailwind CSS
Jeevan Kumar Karre
Jeevan Kumar Karre

Posted on

How can you create dashboard stats card using Tailwind CSS

Image description
The code starts with a

wrapper with the classes "flex", "flex-row", and "flex-wrap". This container gives its children a flexible style that lets them wrap to the next line if they need to.

There are four card parts inside the container. Each is made up of a

element with a different Tailwind CSS class. These classes control the width, padding, and flex behaviour of the card parts to get the layout you want on different screen sizes.

Each part of a card has a

element with the class "h-full rounded-xl bg-white shadow-2xl". This controls how the card looks, including the colour of its background, whether its sides are rounded, and whether it has a shadow.

In the content part of each card, there is a title, a value, and an optional tooltip. The title is shown by a h2 element with the class "text-3xl font-bold" and is centered vertically using the "self-center" class. The number is also a h2 element with the same classes, but the "Total Sales" card has an extra span element with a dollar sign in it. The tooltip is a small piece of text next to the value that shows how much the value has changed. It is hidden by default, but JavaScript and the "x-data" and "x-show" properties make it appear when the mouse is over it.

Below the number, there is an element that looks like a link that says "View more...". It has a class for styling when the mouse is over it.

Each card has a different look based on the colour scheme and SVG icon that go with it. The icons are inserted using an svg> element with the "bi" class, which refers to Bootstrap Icons. Using CSS positioning and change, the icons are put in the middle of a circle-shaped background.

Overall, the code uses both HTML and Tailwind CSS classes to make a nice style for a dashboard's stats cards. The flexible container and responsive classes make sure that the cards adjust to different screen sizes. This makes it good for a responsive site design.

Here is the full code link

Top comments (1)

Collapse
 
respect17 profile image
Kudzai Murimi

Amazing!