About this snippet

Provide clean status updates with an animated battery charging widget. We simulated rising liquid securely with CSS keyframes, seamlessly transitioning from a critical red state up to a healthy green charge.

Size
2.0 KB
Uses
HTML, CSS
Loads
Nothing external
Views
497
<div class="battery-wrapper">
  <div class="battery-terminal"></div>
  <div class="battery-body">
    <div class="charge-liquid"></div>
    <div class="charge-text">Charging</div>
  </div>
</div>
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  margin: 0;
  background: #1e293b;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.battery-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.battery-terminal {
  width: 40px;
  height: 16px;
  background: #475569;
  border-radius: 6px 6px 0 0;
}

.battery-body {
  position: relative;
  width: 140px;
  height: 260px;
  border: 4px solid #475569;
  border-radius: 16px;
  background: #0f172a;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
}

.charge-liquid {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: #ef4444;
  /* Animate height and color securely over 8 seconds */
  animation: fill-battery 8s ease-in-out infinite;
}

.charge-liquid::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -50%;
  width: 200%;
  height: 20px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  animation: wave-horizontal 2s infinite linear;
}

@keyframes fill-battery {
  0% { height: 5%; background: #ef4444; box-shadow: 0 0 20px #ef4444; }
  30% { background: #f59e0b; box-shadow: 0 0 20px #f59e0b; }
  70% { background: #10b981; box-shadow: 0 0 20px #10b981; }
  100% { height: 95%; background: #10b981; box-shadow: 0 0 30px #10b981; }
}

@keyframes wave-horizontal {
  0% { transform: translateX(0); }
  100% { transform: translateX(25%); }
}

.charge-text {
  position: relative;
  z-index: 10;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save