Skip to content

Meter ​

A gauge for a value within a known range, colored good, average or poor on the native meter element.

Installation ​

bash
npx bootcn add meter
bash
pnpm dlx bootcn add meter
bash
yarn dlx bootcn add meter
bash
bunx --bun bootcn add meter

The CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.

Usage ​

Use a meter for a measurement in a range (disk, battery, a score). For the progress of a task, use Progress. Set low, high and optimum: the browser then colors the bar good, average or poor.

Accessibility ​

  • Native <meter> with a <label>: screen readers announce the value.
  • The visible number is hidden from screen readers so it is not read twice.
  • Colors have 3:1 contrast against the background; the number states the value in text.

Dependencies ​

  • Bootstrap 5.3+ CSS.
  • themes/tokens/tokens.css.

Source ​

The exact files the CLI installs (meter@1.0.0). View on GitHub · Report an issue

html
<div class="bootcn-meter">
  <div class="bootcn-meter__head">
    <label for="bootcn-meter-storage">Storage used</label>
    <span aria-hidden="true">72%</span>
  </div>
  <meter
    class="bootcn-meter__bar"
    id="bootcn-meter-storage"
    min="0"
    max="100"
    low="60"
    high="85"
    optimum="20"
    value="72"
  >
    72%
  </meter>
</div>

<div class="bootcn-meter">
  <div class="bootcn-meter__head">
    <label for="bootcn-meter-battery">Battery</label>
    <span aria-hidden="true">18%</span>
  </div>
  <meter
    class="bootcn-meter__bar"
    id="bootcn-meter-battery"
    min="0"
    max="100"
    low="25"
    high="60"
    optimum="100"
    value="18"
  >
    18%
  </meter>
</div>

<div class="bootcn-meter">
  <div class="bootcn-meter__head">
    <label for="bootcn-meter-signal">Signal strength</label>
    <span aria-hidden="true">90%</span>
  </div>
  <meter
    class="bootcn-meter__bar"
    id="bootcn-meter-signal"
    min="0"
    max="100"
    low="30"
    high="70"
    optimum="100"
    value="90"
  >
    90%
  </meter>
</div>
css
.bootcn-meter {
  max-width: 24rem;
}

.bootcn-meter + .bootcn-meter {
  margin-top: 1rem;
}

.bootcn-meter__head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.bootcn-meter__head label {
  margin: 0;
}

/* Good, average and poor: each at least 3:1 against the background. */
.bootcn-meter__bar {
  --bootcn-meter-good: var(--bootcn-success-text);
  --bootcn-meter-average: var(--bootcn-chart-3);
  --bootcn-meter-poor: var(--bootcn-destructive-text);

  display: block;
  width: 100%;
  height: 0.5rem;
  border: 0;
  border-radius: 9999px;
  background: var(--bootcn-muted);
  appearance: none;
}

.bootcn-meter__bar::-webkit-meter-bar {
  height: 0.5rem;
  border: 0;
  border-radius: 9999px;
  background: var(--bootcn-muted);
}

.bootcn-meter__bar::-webkit-meter-optimum-value {
  border-radius: 9999px;
  background: var(--bootcn-meter-good);
}

.bootcn-meter__bar::-webkit-meter-suboptimum-value {
  border-radius: 9999px;
  background: var(--bootcn-meter-average);
}

.bootcn-meter__bar::-webkit-meter-even-less-good-value {
  border-radius: 9999px;
  background: var(--bootcn-meter-poor);
}

.bootcn-meter__bar::-moz-meter-bar {
  border-radius: 9999px;
  background: var(--bootcn-meter-good);
}

.bootcn-meter__bar:-moz-meter-sub-optimum::-moz-meter-bar {
  background: var(--bootcn-meter-average);
}

.bootcn-meter__bar:-moz-meter-sub-sub-optimum::-moz-meter-bar {
  background: var(--bootcn-meter-poor);
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.