AI CSS Animations

Vertical Nav Indicator Hover Effect

A vertical menu on a faint rail: hovering an item springs an accent bar onto the rail and washes a soft tint in from the left. Suits docs sidebars and settings pages.

Also known as: sidebar nav hover, vertical menu active bar, left border indicator.

HTML

<nav class="hfx-nav-vertical-bar">
  <a href="#" aria-current="page">Overview</a>
  <a href="#">Analytics</a>
  <a href="#">Customers</a>
  <a href="#">Settings</a>
</nav>

CSS

.hfx-nav-vertical-bar {
  --c: var(--hfx-color, #3b82f6);
  display: flex;
  align-items: center;
  font: 600 var(--hfx-size, 16px)/1.2 system-ui, sans-serif;
  flex-direction: column;
  align-items: stretch;
  width: 11em;
  border-left: 1px solid color-mix(in srgb, var(--c) 25%, transparent);}
.hfx-nav-vertical-bar a {
  position: relative;
  padding: 0.55em 1em;
  border-radius: 0 0.5em 0.5em 0;
  color: inherit;
  text-decoration: none;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 18%, transparent), color-mix(in srgb, var(--c) 4%, transparent)) no-repeat 0 0 / 0 100%;
  transition: background-size 0.35s cubic-bezier(0.65, 0, 0.35, 1), color 0.25s ease;
}
.hfx-nav-vertical-bar a::before {
  content: "";
  position: absolute;
  left: -0.1em;
  top: 0.3em;
  bottom: 0.3em;
  width: 0.2em;
  border-radius: 1em;
  background: var(--c);
  transform: scaleY(0);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-nav-vertical-bar a:is([aria-current="page"], :hover, :focus-visible) { color: var(--c); }
.hfx-nav-vertical-bar a:is([aria-current="page"], :hover, :focus-visible)::before { transform: scaleY(1); }
.hfx-nav-vertical-bar a:is(:hover, :focus-visible) { background-size: 100% 100%; }

@media (prefers-reduced-motion: reduce) {
  .hfx-nav-vertical-bar, .hfx-nav-vertical-bar *, .hfx-nav-vertical-bar::before, .hfx-nav-vertical-bar::after, .hfx-nav-vertical-bar *::before, .hfx-nav-vertical-bar *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects

Sliding Pill Nav Hover Effect
Directional Underline Nav Hover Effect
Dot Indicator Nav Hover Effect
Strikethrough Nav Hover Effect