Meter

Struct Meter 

Source
pub struct Meter;
Expand description

The <meter> element - represents a scalar measurement within a known range.

§Purpose

The <meter> element represents a scalar measurement within a known range, or a fractional value. Used for displaying measurements like disk usage, voting results, relevance scores, or any gauge-style indicator. Unlike <progress>, which shows task completion, <meter> shows a measurement on a scale.

§Content Categories

  • Flow Content
  • Phrasing Content
  • Palpable Content

§Permitted Content Model

  • Phrasing content (fallback for browsers without meter support, but no <meter> descendants)

§Common Use Cases

  • Disk space usage indicators
  • Battery level displays
  • Rating or scoring displays
  • Temperature or volume gauges
  • Relevance or match percentages

§Key Attributes

  • value: Current value (required)
  • min: Lower bound of range (default: 0)
  • max: Upper bound of range (default: 1)
  • low: Upper bound of “low” range
  • high: Lower bound of “high” range
  • optimum: Optimal value in the range

§Example

<!-- Basic meter -->
<label for="disk-usage">Disk usage:</label>
<meter id="disk-usage" value="0.6">60%</meter>

<!-- Meter with full range specification -->
<label for="battery">Battery level:</label>
<meter id="battery"
       min="0" max="100"
       low="20" high="80"
       optimum="100"
       value="65">65%</meter>

<!-- High value is bad (e.g., CPU usage) -->
<label for="cpu">CPU usage:</label>
<meter id="cpu"
       min="0" max="100"
       low="25" high="75"
       optimum="0"
       value="85">85%</meter>

<!-- Low value is bad (e.g., fuel) -->
<label for="fuel">Fuel level:</label>
<meter id="fuel"
       min="0" max="100"
       low="20" high="80"
       optimum="100"
       value="15">15%</meter>

<!-- Rating display -->
<p>
  Rating:
  <meter min="0" max="5" value="4.2">4.2 out of 5</meter>
  4.2 out of 5 stars
</p>

<!-- Storage usage -->
<p>
  Storage used:
  <meter min="0" max="1000" low="700" high="900" value="852">
    852 GB of 1000 GB
  </meter>
  852 GB / 1 TB
</p>

<!-- Temperature gauge -->
<label for="temp">Room temperature:</label>
<meter id="temp"
       min="0" max="50"
       low="18" high="28"
       optimum="22"
       value="25">25°C</meter>

§Accessibility

  • Provide text content as fallback
  • Use labels to describe what’s being measured
  • Ensure color isn’t the only indicator of status
  • Browser typically colors the meter based on value ranges
  • Screen readers announce the value and context

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Meter

Source§

const TAG: &'static str = "meter"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl<T: PhrasingContent> CanContain<T> for Meter

Source§

impl FlowContent for Meter

Source§

impl PalpableContent for Meter

Source§

impl PhrasingContent for Meter

Auto Trait Implementations§

§

impl Freeze for Meter

§

impl RefUnwindSafe for Meter

§

impl Send for Meter

§

impl Sync for Meter

§

impl Unpin for Meter

§

impl UnwindSafe for Meter

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.