• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

CSS Bar Charts Utilizing Trendy Capabilities

Admin by Admin
February 5, 2026
Home Coding
Share on FacebookShare on Twitter


New CSS options can typically make it simpler and extra environment friendly to code designs we already knew learn how to create. This effectivity may stem from decreased code or hacks, or improved readability because of the new options.

In that spirit, let’s revamp what’s beneath the hood of a bar chart.

We start by laying out a grid.

.chart {
  show: grid;
  grid-template-rows: repeat(100, 1fr);
  /* and so forth. */
}

The chart metric relies on share, as in “some quantity out of 100.” Let’s say we’re working with a grid containing 100 rows. That must stress take a look at it, proper?

Subsequent, we add the bars to the grid with the grid-column and grid-row properties:

.chart-bar {
  grid-column:  sibling-index();
  grid-row: span attr(data-value quantity);
  /* and so forth. */
}

Proper off the bat, I need to notice a few issues. First is that sibling-index() perform. It’s model new and has incomplete browser help as of this writing (come on, Firefox!), although it’s at present supported within the newest Chrome and Safari (however not on iOS apparently). Second is that attr() perform. We’ve had it for some time, nevertheless it was just lately upgraded and now accepts data-attributes. So when we've a type of in our markup — like data-value="32" — that’s one thing the perform can learn.

With these in place, that’s actually all we have to create a fairly darn good bar chart in vanilla CSS! The next demo has fallbacks in place to be able to nonetheless see the ultimate lead to case your browser hasn’t adopted these new options:

Sure, that was simple to do, nevertheless it’s finest to know precisely why it really works. So, let’s break that down.

Robotically Establishing Grid Columns

Declaring the sibling-index() perform on the grid-column property explicitly locations the listing objects in consecutive columns. I say “specific” as a result of we’re telling the grid precisely the place to put every merchandise by its data-value attribute within the markup. It goes first

  • in first column, second
  • in second column, and so forth.

    That’s the ability of sibling-index() — the grid intelligently generates the order for us with out having to do it manually by way of CSS variables.

    /* First bar: sibling-index() = 1 */
    grid-column: sibling-index();
    
    /* ...leads to: */
    grid-column: 1;
    grid-column-start: 1; grid-column-end: auto;
    
    /* Second bar: sibling-index() = 2 */
    grid-column: sibling-index();
    
    /* ...leads to: */
    grid-column: 2;
    grid-column-start: 2; grid-column-end: auto;
    
    /* and so forth. */

    Robotically Establishing Grid Rows

    It’s just about the identical factor! However on this case, every bar occupies a sure variety of rows based mostly on the share it represents. The grid will get these values from the data-value attribute within the markup, successfully telling the grid how tall every bar within the chart needs to be.

    /* First bar: data-value="32" */
    grid-row: span attr(data-value quantity);
    
    /* ...leads to: */
    grid-row: span 32
    
    /* Second bar: data-value="46" */
    grid-row: span attr(data-value quantity);
    
    /* ...leads to: */
    grid-row: span 46

    The attr() perform, when supplied with a knowledge kind parameter (the parameter worth quantity in our case), casts the worth retrieved by attr() into that particular kind. In our instance, the attr() perform returns the worth of data-value as a kind, which is then used to find out the variety of rows to span for every bar.

    Let’s Make Completely different Charts!

    Since we've the nuts and bolts down on this method, I figured I’d push issues a bit and exhibit how we are able to apply the identical methods for all types of CSS-only charts.

    For instance, we are able to use grid-row values to regulate the vertical route of the bars:

    Or we are able to skip bars altogether and use markers as a substitute:

    We are able to additionally swap the columns and rows for horizontal bar charts:

    Wrapping up

    Fairly thrilling, proper? Simply take a look at all of the methods we used to drag these things off earlier than the times of sibling-index() and an upgraded attr():

  • Tags: BarChartsCSSfunctionsmodern
    Admin

    Admin

    Next Post
    The Washington Put up is retreating from Silicon Valley when it issues most

    The Washington Put up is retreating from Silicon Valley when it issues most

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Recommended.

    When do you have to do search engine optimization?

    When do you have to do search engine optimization?

    May 9, 2025
    Q&A with Gokul Rajaram, investor and a former product chief at Google, Meta, and others, on AI altering product growth, constructing advert companies, and extra (Patrick O’Shaughnessy/Make investments Like The Finest on YouTube)

    Q&A with Gokul Rajaram, investor and a former product chief at Google, Meta, and others, on AI altering product growth, constructing advert companies, and extra (Patrick O’Shaughnessy/Make investments Like The Finest on YouTube)

    January 31, 2026

    Trending.

    The right way to Defeat Imagawa Tomeji

    The right way to Defeat Imagawa Tomeji

    September 28, 2025
    Introducing Sophos Endpoint for Legacy Platforms – Sophos Information

    Introducing Sophos Endpoint for Legacy Platforms – Sophos Information

    August 28, 2025
    Satellite tv for pc Navigation Methods Going through Rising Jamming and Spoofing Assaults

    Satellite tv for pc Navigation Methods Going through Rising Jamming and Spoofing Assaults

    March 26, 2025
    How Voice-Enabled NSFW AI Video Turbines Are Altering Roleplay Endlessly

    How Voice-Enabled NSFW AI Video Turbines Are Altering Roleplay Endlessly

    June 10, 2025
    Learn how to Set Up the New Google Auth in a React and Specific App — SitePoint

    Learn how to Set Up the New Google Auth in a React and Specific App — SitePoint

    June 2, 2025

    AimactGrow

    Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

    Categories

    • AI
    • Coding
    • Cybersecurity
    • Digital marketing
    • Gaming
    • SEO
    • Technology

    Recent News

    Unrestricted AI Video Generator (With out Watermark)

    Unrestricted AI Video Generator (With out Watermark)

    February 12, 2026
    Beastars ultimate season half 2 launch date officiall introduced

    Beastars ultimate season half 2 launch date officiall introduced

    February 12, 2026
    • About Us
    • Privacy Policy
    • Disclaimer
    • Contact Us

    © 2025 https://blog.aimactgrow.com/ - All Rights Reserved

    No Result
    View All Result
    • Home
    • Technology
    • AI
    • SEO
    • Coding
    • Gaming
    • Cybersecurity
    • Digital marketing

    © 2025 https://blog.aimactgrow.com/ - All Rights Reserved