Label
Anatomy
Standalone form label element for associating text with form controls. Supports required field indicators with built-in accessibility.
maud_ui::primitives::label
Props
Generated from public Rust fields. Defaults are evaluated from the implementation.
| Prop | Type | Default | Description |
|---|---|---|---|
text | String | "" | Label text |
html_for | Option<String> | None | ID of associated form control |
required | bool | false | Whether the field is required |
disabled | bool | false | Whether the label should appear disabled |
Examples
Variants
Default
Required
Disabled
With input
Usage and composition
Import
use maud_ui::primitives::label::{self, Props};
Example
use maud::html;
use maud_ui::primitives::label;
html! {
div class="mui-field" {
(label::render(label::Props {
text: "Email address".into(),
html_for: Some("email-input".into()),
required: false,
disabled: false,
}))
input class="mui-input" id="email-input" type="email" placeholder="you@example.com" {}
}
}
Variants
| Variant | Configuration | Use Case |
|---|---|---|
| Default | All false | Standard label for optional fields. |
| Required | required: true | Label for mandatory form fields; displays required indicator. |
| Disabled | disabled: true | Label associated with disabled input (e.g., read-only fields). |
| Required Disabled | Both true | Combination of required and disabled states. |
Helpers
None. The component is a minimal wrapper around the HTML <label> element.
Related
Input, Checkbox, Radio Button, Textarea, Native Select, Number Field.
Shadcn reference
https://ui.shadcn.com/docs/components/base/label
Accessibility
html_forattribute: Creates semantic association with the form control, improving usability for all users and assistive technology.- Required indicator: Uses
aria-label="required"on the<span>containing the asterisk, ensuring screen readers announce the required status without redundant text. - Disabled state: Applies visual class but does NOT add
disabledattribute (only the input should be disabled). Visual styling communicates disabled state.