DEV Community

Cover image for CSS Bar Chart
codingdudecom
codingdudecom

Posted on

CSS Bar Chart

A while back I had a project involving the creation of a lightweight chart library. In my research I tried out several approaches from JS with canvas to simple HTML & CSS.

In the end I created a commercial charts library JavaScript using JS & canvas, but I kept my intermediary attempts.

How to Make a Bar Chart Using Only HTML and CSS

The most interesting solution to creating a lightweight bar chart was to use a plain old HTML table element that contained the data for the bar chart and transform that using only CSS to turn it into a bar chart.

CSS Bar Chart

Basically I took the HTML code for the table that looked like this:

<table class="graph">
    <caption>Describe this Data</caption>
    <thead>
        <tr>
            <th scope="col">Item</th>
            <th scope="col">Percent</th>
        </tr>
    </thead><tbody class="horizontal">
        <tr style="height:85%">
            <th scope="row">Your Blog</th>
            <td><span>85%</span></td>
        </tr>
...
Enter fullscreen mode Exit fullscreen mode

See the Pen Bar Chart HTML Only (table version alternative) by Ion Emil Negoita
(@inegoita) on CodePen.

In Conclusion

If you want to read more about 3 other methods for this, check out this detailed article on how to make a CSS bar chart using only HTML & CSS.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay