Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <table class="chart" style="width:500px;">

    <caption> CSS Pie Chart from HTML Table </caption>

    <thead>
        <tr>
            <th scope="col"> Month </th>
            <th scope="col"> Stats </th>
        </tr>
    </thead>

    <tbody>
        <tr>
            <th scope="row"> 2005 </th>
            <td style="--start: 0; --size: 0.10; --color: rgb(240, 100, 100);"> <span class="data"> 100 </span> </td>
        </tr>
        <tr>
            <th scope="row"> 2010 </th>
            <td style="--start: 0.10; --size: 0.18; --color: rgb(130, 190, 255);"> <span class="data"> 180 </span> </td>
        </tr>
        <tr>
            <th scope="row"> 2015 </th>
            <td style="--start: 0.28; --size: 0.56; --color: rgb(140, 220, 120);"> <span class="data"> 560 </span> </td>
        </tr>
        <tr>
            <th scope="row"> 2020 </th>
            <td style="--start: 0.84; --size: 0.16; --color: rgb(190, 130, 255);"> <span class="data"> 160 </span> </td>
        </tr>
    </tbody>

</table>

              
            
!

CSS

              
                /*
 * CSS Pie Chart from HTML tables.
 *
 * TODO:
 * ~~~~~
 * Do the same without the "--start" variable.
 * Find a way to move the accumulated amount of
 * the "--size" vars to the next TR>TD.
 * Try counters, combinators (~ general sibling
 * and + adjacent sibling) and other techniques.
 */

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  background-color: #001;
  color: #fff;
}

@mixin position-fullwidth {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;

  width: 100%;
  height: 100%;

  border-radius: 50%;

  display: flex;
  justify-content: center;
}

.chart {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;

  caption,
  thead,
  tfoot {
    display: none;
  }

  tbody {
    position: relative;

    // Create a circle
    display: block;
    width: 100%;
    height: 0;               // Old hack before "aspect-ratio"
    padding-block-end: 100%; // makes height 100% of the width
    aspect-ratio: 1 / 1;
    border-radius: 50%;

    tr {
      th {
        display: none;
      }

      td {
        @include position-fullwidth();

        transform: rotate( calc( 1turn * var( --start, 0 ) ) );

        background: conic-gradient(
          var( --color, transparent ) 0 calc( 100% * var( --size, 0 ) ),
          transparent 0 100%
        );

        // background-color: var(--color);
        // -webkit-mask-image: conic-gradient(red calc(100% * var(--size)), transparent calc(100% * var(--size)));
        // mask-image: conic-gradient(red calc(100% * var(--size)), transparent calc(100% * var(--size)));

        .data {
          @include position-fullwidth();

          transform: rotate( calc( 0.5turn * var( --size, 0 ) ) );
          // top: -1.5rem;
        }
      }
    }
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console