Message component displays information related to another element such as invalid input.

import { Message } from 'primereact/message';

Text to display is defined with the text property.

<Message text="Username is required" />

The severity property specifies the type of the message.

<Message severity="info" text="Info Message" />
<Message severity="success" text="Success Message" />
<Message severity="warn" text="Warning Message" />
<Message severity="error" text="Error Message" />
<Message severity="secondary" text="Secondary Message" />
<Message severity="contrast" text="Contrast Message" />

Message component is handy when displaying error messages next to form elements.

<div className="flex flex-wrap align-items-center mb-3 gap-2">
    <label htmlFor="username" className="p-sr-only">Username</label>
    <InputText id="username" placeholder="Username" className="p-invalid mr-2" />
    <Message severity="error" text="Username is required" />
<div className="flex flex-wrap align-items-center gap-2">
    <label htmlFor="email" className="p-sr-only">Email</label>
    <InputText id="email" placeholder="Email" className="p-invalid mr-2" />
    <Message severity="error" />

Custom content is displayed with the content property.

    border: 'solid #696cff',
    borderWidth: '0 0 0 6px',
    color: '#696cff'
className="border-primary w-full justify-content-start"

Screen Reader

Message components use alert role that implicitly defines aria-live as "assertive" and aria-atomic as "true". Since any attribute is passed to the root element, attributes like aria-labelledby and aria-label can optionally be used as well.

Close element is a button with an aria-label that refers to the aria.close property of the locale API by default, you may usecloseButtonProps to customize the element and override the default aria-label.

Close Button Keyboard Support

enterCloses the message.
spaceCloses the message.