Skip to content

Instantly share code, notes, and snippets.

@jensgro
Forked from danfascia/svg-pie-charts.html
Created February 9, 2023 22:20
Show Gist options
  • Save jensgro/4040e652c168e8981c7f8f25dbd334cf to your computer and use it in GitHub Desktop.
Save jensgro/4040e652c168e8981c7f8f25dbd334cf to your computer and use it in GitHub Desktop.
Neat responsive SVG pie charts (no javascript)
<!--
Neat way to render responsive pie charts in HTML with SVGs and CSS from https://www.smashingmagazine.com/2015/07/designing-simple-pie-charts-with-css/
-->
<style>
svg.piechart {
transform: rotate(-90deg);
background: #B0233B;
border-radius: 50%;
}
svg.piechart circle {
fill: #B0233B;
stroke: #5ABBA2;
stroke-width: 32;
stroke-dasharray: 0 100; /* 0 = 0% to be set inline on the circle attribute to change the %%*/
}
</style>
<!-- SVG Pie Chart: Adjust percentage by changing the first number of stroke-dasharray i.e. 37 100 = 37% -->
<svg class="piechart" viewBox="0 0 32 32">
<circle style="stroke-dasharray: 37 100;" r="16" cx="16" cy="16" />
</svg>
<!-- / SVG Pie Chart -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment