An alert is a v-sheetthat specializes in getting the user’s attention. While similar to v-bannerin functionality, v-alert is typically inline with content and used multiple times throughout an application.
The v-alert component is a callout element designed to attact the attention of a user. Unlike v-banner, the v-alert component is intended to be used and re-used throughout your application. An alert’s color is derived from its type property which corresponds to your application’s contextual theme colorsand iconfont aliases.
In addition to the standard v-sheetproperties such as elevation, dimension, and border-radius, the v-alert component supports v-model, variants, and density.
Alerts have 4 contextual states: success, info, warning, and error. Each state has a default color and icon associated with it. When a type is not provided, the v-alert component defaults to a greyish background.
With a basic alert rendered, add your choice of contextual type. The following example puts the v-alert component in a success state:
The type property acts as a shorthand for a color and icon combination, you can use both props individually to achieve the same effect. The following example produces the same result as using type=“success” by defining a custom color and using the icon lookup table to get the globally defined success icon:
<v-alertcolor="success"icon="$success"title="Alert title"text="Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi, ratione debitis quis est labore voluptatibus..."></v-alert>
The v-alert component has the ability to reduce its height in intervals using the density prop. This is useful when you need to reduce the vertical space a component needs. The following example reduces the vertical space by using density=“compact”:
The density prop supports 3 levels of component height; default, comfortable, and compact.
The v-alert has 6 style variants, elevated, flat, tonal, outlined, text, and plain. By default, the v-alert component is flat; which means that it has a solid background and no box-shadow (elevation). The following example modifies the overall styling of the alert with a custom variant:
The closable prop adds a v-iconon the far right, after the main content. This control hides the v-alert when clicked, setting it’s internal model to false. Manually control the visibility of the alert by binding v-model or using model-value. The following example uses a dynamic model that shows and hides the v-alert component:
The close icon automatically applies a default aria-label and is configurable by using the close-label prop or changing close value in your locale.
For more information on how to global modify your locale settings, navigate to the Internationalization page.
The colored-border prop removes the alert background in order to accent the border prop. If a type is set, it will use the type’s default color. If no color or type is set, the color will default to the inverted color of the applied theme (black for light and white/gray for dark).
The icon prop allows you to add an icon to the beginning of the alert component. If a type is provided, this will override the default type icon. Additionally, setting the icon prop to false will remove the icon altogether.
The outlined prop inverts the style of an alert, inheriting the currently applied color, applying it to the text and border, and making its background transparent.
By default, v-alert components are assigned the WAI-ARIArole of alertwhich denotes that the alert "is a live region with important and usually time-sensitive information." When using the closable prop, the close icon will receive a corresponding aria-label. This value can be modified by changing either the close-label prop or globally through customizing the Internationalization’s default value for the close property.
Ready for more?
Continue your learning with related content selected by the Team or move between pages by using the navigation links below.