# Email field

A visible label, a helpful hint, and an error that explains the next step.

## Usage

Place this field inside a form and validate on submit or blur. Browser validation helps users; validate again on the server before processing any real submission.

Save the JSX and CSS Module in the same folder in a React project with CSS Modules support. Controlled components need parent state and change handlers.

## JSX

```jsx
"use client";
import styles from "./EmailField.module.css";
import { useId } from "react";
export default function EmailField({
  value = "",
  onChange,
  error = "",
  label = "Email address",
}) {
  const id = useId();
  return (
    <div className={styles.field}>
      <label htmlFor={id}>{label}</label>
      <input
        id={id}
        type="email"
        autoComplete="email"
        required
        value={value}
        onChange={(event) => onChange?.(event.target.value)}
        aria-invalid={Boolean(error)}
        aria-describedby={id + "-hint"}
        placeholder="you@company.com"
      />
      <p id={id + "-hint"}>
        {error || "Use the address where you want to receive updates."}
      </p>
    </div>
  );
}

```

## CSS

```css
.field {
  width: 100%;
  font: 14px/1.5 var(--tdp-font, "DM Sans", system-ui, sans-serif);
  color: var(--tdp-text, #302e2b);
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 9px;
}
.field input {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--tdp-control-height, 48px);
  border: 1px solid #a3a3a3;
  border-radius: var(--tdp-radius, 8px);
  background: var(--tdp-surface, #fffdfa);
  color: var(--tdp-text, #302e2b);
  padding: 0 15px;
  font: 16px var(--tdp-font, "DM Sans", system-ui, sans-serif);
}
.field input[aria-invalid="true"] {
  border-color: #a4382e;
}
.field p {
  margin: 9px 0 0;
  color: var(--tdp-muted, #6b625b);
  font-size: 13px;
}
.field:has(input[aria-invalid="true"]) p {
  color: #a4382e;
}
.field:focus-visible,
.field :where(button, input, summary):focus-visible {
  outline: 3px solid var(--tdp-focus, #7851a9);
  outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
  .field,
  .field :where(button, input, summary, span) {
    transition: none !important;
    animation: none !important;
  }
}

```

## Props

- value (string): Controlled email value.
- onChange (function): Receives the entered string.
- error (string): Validation message, empty when valid.
- label (string): Visible input label.

## Accessibility

The label is connected with useId. The hint or error is linked through aria-describedby and aria-invalid reflects the error state. Do not use the placeholder as the only label.

Check accessibility again after customizing the component.

[Browse all components](/resources/components/)

Canonical: https://designproject.io/resources/components/email-field/

## Keep learning

- [How to create a UI color palette, step by step](https://designproject.io/resources/guides/create-ui-color-palette/)
- [Product design glossary: 44 terms explained](https://designproject.io/resources/glossary/)
- [How to choose font pairings for a product interface](https://designproject.io/resources/guides/choose-font-pairings/)
