Skip to content

Lost connection alert in HTML and CSS

A banner that warns visitors when they lose the network and announces when it is back, using browser events, with no request.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Alerte de connexion perdue</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <section class="acp" data-acp aria-labelledby="acp-titre">
        <div class="acp-banner" role="status" data-acp-banner hidden>
script.js
document.querySelectorAll("[data-acp]").forEach((root) => {
  const on = (el, type, fn) => el.addEventListener(type, fn);
  const offs = [];
  const banner = root.querySelector("[data-acp-banner]");
  const msg = root.querySelector("[data-acp-msg]");
  let timer = 0;

  const show = (online) => {
    window.clearTimeout(timer);
    banner.dataset.acpState = online ? "online" : "offline";
    msg.textContent = online
      ? "Connexion rétablie : vous pouvez reprendre là où vous en étiez."
style.css
:root {
  --acp-card: #ffffff;
  --acp-text: #1c2321;
  --acp-muted: #4d5754;
  --acp-soft: #f2f5f4;
  --acp-off-bg: #fff7ed;
  --acp-off-line: #b45309;
  --acp-off-text: #7c2d12;
  --acp-on-bg: #f0fdf4;
  --acp-on-line: #15803d;
  --acp-on-text: #14532d;
  --demo-bg: #e9eeec;

Free component: copy it freely, including for commercial projects.

Toasts and alerts components in HTML and CSS
  • A bell with an unread badge that opens a notification panel: icons by type, read and unread items told apart, and a "Mark all as read" button.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • The four classic interface messages: information, success, warning and error.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three callouts for technical documentation: note, tip and warning.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A notice warning of a scheduled service interruption, with date, time and impact.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A dashed callout highlighting an offer and its code, with the end date.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An announcement bar at the top of the page with a link and a button to close it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component