Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Button with Notification Badge</title> <style> /* Component: Button with Notification Badge Description: A button with a small badge for counters or status indicators. */ :root { --badge-btn-bg: #007bff; --badge-btn-text-color: #ffffff; --badge-btn-bg-hover: #0069d9; --badge-bg-color: #dc3545; /* Red for high visibility */ --badge-text-color: #ffffff; --badge-focus-outline: #007bff; } .badge-btn-container-1 { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; display: flex; justify-content: center; align-items: center; padding: 2rem; background-color: #f8f9fa; } .badge-btn-1 { position: relative; /* Required for absolute positioning of the badge */ display: inline-block; padding: 0.9rem 1.8rem; font-size: 1.1rem; font-weight: 600; color: var(--badge-btn-text-color); background-color: var(--badge-btn-bg); border: none; border-radius: 8px; cursor: pointer; text-decoration: none; transition: background-color 0.2s ease; } .badge-btn-1:hover { background-color: var(--badge-btn-bg-hover); } .notification-badge { position: absolute; top: -10px; right: -10px; display: flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 6px; font-size: 0.8rem; font-weight: 700; color: var(--badge-text-color); background-color: var(--badge-bg-color); border-radius: 12px; border: 2px solid #ffffff; /* Gives separation from the button */ } .badge-btn-1:focus-visible { outline: 3px solid var(--badge-focus-outline); outline-offset: 2px; } </style> </head> <body> <div class="badge-btn-container-1"> <button type="button" class="badge-btn-1"> <!-- For screen readers to announce the full context --> <span>Notifications</span> <span class="visually-hidden">, 3 new items</span> <!-- The visual badge, hidden from screen readers to prevent repetition --> <span class="notification-badge" aria-hidden="true">3</span> </button> <style> /* Simple visually-hidden class for accessibility */ .visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; } </style> </div> </body> </html>