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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more