🚀 Ship faster with premium components 🚀
Search documentation v1.1.0

Gauge

Represent values within a range using an arc

Source Report Issue
Command docs
How to add this block to your project
npm run add Gauge

Use the Gauge component to visually represent values within a range (like speed, progress, or performance) using an arc. They are perfect for:

Preview
0%Progress
Unlock code
How to use the Gauge component in Astro
<Gauge
percentage={72}
value="0%"
label="Progress"
/>

The only required prop for the Gauge component is percentage. You can however set additional labels using the value and label props. Note that the Gauge component is animated by default, meaning it’ll start count from 0% on load. Thus, when using the component with animations enabled, it’s recommended to set this to 0% for proper initial display.

Colors

You can change the colors of the gauge using the following three props:

0%Colored gauge
Unlock code
How to use custom colors
<Gauge
percentage={72}
value="0%"
label="Colored gauge"
background="transparent"
colorFrom="var(--w-color-info)"
colorTo="var(--w-color-alert)"
/>

You can hide the background by setting it to transparent. Using two separate fill colors makes it possible to create gradients. If you need a custom solid color, simply set both colors to the same values.

Styles

The style of the gauge can be updated using the following three props:

0%Styled gauge
Unlock code
How to further style the gauge
<Gauge
percentage={72}
value="0%"
label="Styled gauge"
width={5}
rotation={10}
rounded={false}
/>

Animations

By default, the component is animated. You can change animation speed using the animationSpeed prop, or turn off animation entirely by setting animated to false:

Unlock code
Use milliseconds when setting animation speed
<Gauge
percentage={72}
value="0%"
label="Custom animation speed"
animationSpeed={5000} {/* Default is 2000ms */}
/>
Unlock code
How to disable animation
<Gauge
percentage={72}
value="72%"
label="No animation"
animated={false} {/* Default to true */}
/>

Note that when disabling animation, you want to set value to the value of the percentage prop, as it’ll not be updated automatically.

Global Settings

The Gauge component can be customized per component call. However, if you’re dealing with multiple Gauge components on your page and you want to share styles, you can also customize the following settings globally:

Unlock code
How to style gauges globally in your CSS
html body {
--w-gauge-width: 10;
--w-gauge-bg: rgba(255, 255, 255, 0.2);
--w-gauge-rotation: 0deg;
--w-gauge-animation-speed: 2s;
}

API

Unlock code
Component API reference
type GaugeProps = {
percentage: number
value?: string
label?: string
background?: string
colorFrom?: string
colorTo?: string
width?: number
rotation?: number
rounded?: boolean
animationSpeed?: number
animated?: boolean
className?: string
}
PropDefaultPurpose
percentage 0 Sets the percentage value of the gauge between 0 and 100%.
value - Sets a bolded value on the gauge. Use the percentage value if the gauge is not animated.
label - Sets a label under the value.
background #ffffff33 Sets the background color.
colorFrom primary Sets the starting fill color.
colorTo primary Sets the ending fill color.
width 10 Sets the width of the stroke.
rotation 0 Sets a rotation for the gauge.
rounded true Sets the edges to rounded.
animationSpeed 2000 Sets the speed of the animation when animated is set to true.
animated true Animates the gauge from 0% to the value of the percentage prop.
className - Pass additional CSS classes for the Gauge component.