Label
The text of a form label, with an optional required indicator. Put it inside your own <label>, or in the label slot of a field.
fandry-label
Example
Link to section ExampleCustom colors and parts
Link to section Custom colors and partsThe same component with a few --fd-* tokens set around it and its parts restyled. The code is under Parts below.
Props
Link to section Props| Prop | Type | Default | Description |
|---|---|---|---|
required | boolean | false | Shows the required asterisk. It is only the mark: set required on your control as well. In a field's label slot the field shows it instead, from its own required. |
html-for | string | — | Deprecated: it does nothing. The for goes on the <label> you wrap this in. |
Parts
Link to section PartsStyle the elements inside the component from your own CSS with ::part(). Every fandry component renders in native shadow DOM, so parts work on LWR and Salesforce alike. For colors, spacing, radius and type across many components, set the --fd-* tokens instead. The code for the "Custom colors and parts" example above:
| Part | Description |
|---|---|
base | The outermost element. |
required | The required-field asterisk. |
<!-- template -->
<div class="brand stack narrow">
<label for="theme-email"><fandry-label required>Email</fandry-label></label>
<input id="theme-email" type="email" class="native-input" placeholder="you@brand.com" />
</div>
/* css */
/* Scoped to this demo. Set the same --fd-* tokens on :root to theme
every fandry-* component on the site. */
.brand {
--fd-text: 160 40% 14%;
}
fandry-label::part(base) {
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
fandry-label::part(required) {
color: hsl(160 84% 26%);
}
Code
Link to section Code<!-- with your own control -->
<label for="username"><fandry-label required>Username</fandry-label></label>
<input id="username" />
<!-- in a field's label slot: it looks like the field's label, and the
field shows the asterisk -->
<fandry-input required>
<fandry-label slot="label">Username</fandry-label>
</fandry-input>
Why you write the <label> yourself
A label finds its control by id, and the browser looks an id up inside one shadow root only. A <label> rendered inside fandry-label could never reach a control outside it: it would look right, give the control no name for a screen reader, and do nothing when clicked.
So you write the <label>, beside its control, and fandry-label goes inside it as the text. That is how web components work, not something particular to this library: each component is a tree of its own, so two elements that refer to each other have to be in the same one.
The fields (fandry-input, fandry-textarea, fandry-select, fandry-combobox, fandry-lookup) follow the same rule from the inside. Each renders its own <label> next to its own control, so they take the label as a prop or a slot and need no fandry-label.