Button with Notification Badge Template

Draw attention to new items or updates with this button and notification badge combination.

This is a standard and highly effective way to signal unread messages, new alerts, or the number of items in a shopping cart.

Screenshot of a button with a small red badge showing a notification count.

Get Source Code Preview

About the Button with Notification Badge

A notification badge is a small overlay on a button that indicates a change in status or a number of new items requiring the user's attention. Its bright color and strategic placement make it stand out. For accessibility, it's important that the button's text or aria-label reflects the notification's content, so the information isn't purely visual.

Features

Code Breakdown

The structure consists of a button element with its position set to relative. Inside the button are the button text and a span element for the badge. The badge's position is set to absolute, which allows it to be positioned relative to the corners of its parent button. By adding aria-hidden="true" to the badge and including its information in the button's primary text, we ensure the component is usable by everyone.

Code

Here is the complete code for the button with a notification badge.

View Output