
# Label



> Label component is used as a text label for items in an interface. Most often used inside other form components.

## Examples

### Default

```tsx
import { Label } from "@kesko/components";

export default () => (
  <Label>Default label</Label>
);

```

```html
<label class="k-label">Default label</label>
```

### Custom style

```tsx
import { Label } from "@kesko/components";

const subtle = {
  "--k-label-text": "var(--k-color-text-dim)",
  "--k-label-weight": "var(--k-font-weight-medium)",
  "--k-label-required": "var(--k-color-status-error)",
};

export default () => (
  <Label required style={subtle}>
    Custom label
  </Label>
);

```

```html
<label
  class="k-label"
  style="
    --k-label-text: var(--k-color-text-dim);
    --k-label-weight: var(--k-font-weight-medium); 
    --k-label-required: var(--k-color-status-error);"
>Custom label<span class="k-label-required" aria-hidden="true">*</span></label>
```

### Required

```tsx
import { Label } from "@kesko/components";

export default () => (
  <Label required>Required label</Label>
);

```

```html
<label class="k-label">Required label<span class="k-label-required" aria-hidden="true">*</span></label>
```


## Props

- `htmlFor` — `string` The `id` of the form control this label describes.
- `required` — `boolean` (default: `false`) Shows a required marker after the text. The marker is decorative, set `required` on the control as well.

## CSS custom properties

- `--k-label-text` (default: `var(--k-color-text-base)`) Overrides the text color.
- `--k-label-weight` (default: `var(--k-font-weight-bold)`) Overrides the font weight.
- `--k-label-size` (default: `var(--k-font-size-md)`) Overrides the font size.
- `--k-label-required` (default: `currentColor`) Overrides the required indicator color. Defaults to the label text color.

## Accessibility

Label is built on a native `<label>`, so it behaves as expected with assistive technologies.

- **Point it at the control.** Set `htmlFor` to the control's `id`. That is what makes a screen reader read the label as the control's name and what makes a click on the label focus the control. Wrapping the control inside the label works too.
- **Keep it visible.** Placeholder text disappears as soon as someone types. If a label really has no room, wrap it in [Visually Hidden](/components/visually-hidden/) rather than leaving it out.
- **`required` only draws the marker.** It is hidden from assistive technology. Set `required` on the control as well, which is what gets announced and what blocks the form from submitting.
- **Check contrast if you override the color.** `--k-label-text` needs 4.5:1 against the surface the label sits on. Verify with the [WebAIM contrast checker](https://webaim.org/resources/contrastchecker/).

See the [accessibility guidelines](/accessibility/) and the [A11Y checklist](/a11y-checklist/) for more details.

## Integration

Install `@kesko/components` together with `@kesko/css`, which provides the design tokens and base styles it depends on, and `@kesko/themes` for your brand:

```sh
npm install @kesko/components @kesko/css @kesko/themes
```

Then load the base stylesheet and one brand theme once, in your app's entry point or root layout. Leave out `@kesko/css/components`: it mirrors the component styles for plain HTML, and `@kesko/components` already ships them.

```tsx
import "@kesko/css";
import "@kesko/themes/dist/k-rauta.css";
```

Finally, import the component into your project:

```tsx
import { Label } from "@kesko/components";
```

Projects without React get the same markup and styling from `@kesko/css` by importing the base stylesheet, the `components` add-on and a brand theme, in that order:

```css
@import "@kesko/css";
@import "@kesko/css/components";
@import "@kesko/themes/dist/k-rauta.css";
```

The HTML examples above show the exact markup to copy.

## Resources

- [Usage guidelines](/components/usage/) — Learn how to use the component library with React, Next.js, or basic HTML.
- [Localization](/localization/) — How to translate the components for multiple languages.
- [CSS Framework](/css/) — Utilities and tokens for everything the components don’t cover.
- [Themes](/themes/) — How to customize the component library theme.
- [Accessibility checklist](/a11y-checklist/) — Interactive, browser-based Kesko accessibility checklist.

