useId generates stable unique IDs that work with server-side rendering and hydration. Use it to connect <label htmlFor> with <input id>, aria-labelledby, and other accessibility attributes.
Stable IDs Across Server and Client
Before useId, developers used incrementing counters or Math.random() for IDs — both break SSR hydration or uniqueness guarantees. useId produces consistent IDs per component instance across server and client.
Do not use useId for list keys. Keys should come from your data. useId is for accessibility wiring within one component instance.
function EmailField() {
const id = useId();
return (
<>
<label htmlFor={id}>Email</label>
<input id={id} type="email" aria-describedby={`${id}-hint`} />
<p id={`${id}-hint`}>We'll never share your email.</p>
</>
);
}
One useId call can prefix multiple related element IDs.