The error element

Categories:
Flow content.
Phrasing content.
Interactive content.
Reassociateable form-associated element.
Palpable content.
Contexts in which this element can be used:
Where phrasing content is expected.
Content model:
Phrasing content, but with no descendant labelable elements unless it is the element's labeled control, and no descendant error elements.
Content attributes:
Global attributes
form - Associates the control with a form element
for - Associate the label with form control
Tag omission in text/html:
Neither tag is omissable
Allowed ARIA role attribute values:
error (default - do not set)
Allowed ARIA state and property attributes:
Global aria-* attributes
DOM interface:
interface HTMLErrorElement : HTMLElement {
  readonly attribute HTMLFormElement? form;
           attribute DOMString htmlFor;
  readonly attribute HTMLElement? control;
};

The error element represents an error message. The error can be associated with a specific control by using the for attribute.

The following example shows an invalid form control which is labelled with an error element.

<label for="username">Username</label>
<input type="text"
  id="username"
  name="username"
  placeholder="Lowercase only, e.g.: soren"
  pattern="[a-z]{3,15}">
<error for="username">Username should only contain lowercase letters. e.g. soren</error>