Simple dynamic effect of stroke dashuffset in SVG


Property introduction
The stroke dashoffset property specifies the distance from the dash pattern to the beginning of the path
If a < percentage > value is used, this value represents a percentage of the current viewport.
The value can be negative
Let’s see the effect first

<button class="menu__item" style="--bgColorItem: #f54888;">
  <svg class="icon" viewBox="0 0 24 24">
    <path  d="M6.7,4.8h10.7c0.3,0,0.6,0.2,0.7,0.5l2.8,7.3c0,0.1,0,0.2,0,0.3v5.6c0,0.4-0.4,0.8-0.8,0.8H3.8
    <path  d="M3.4,12.9H8l1.6,2.8h4.9l1.5-2.8h4.6"/>
html {

    box-sizing: border-box;
    --bgColorMenu : #1d1d27;
    --duration: .7s;    
    --timeOut: none;

html *,
html *::before,
html *::after {
    box-sizing: inherit;

    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    align-items: center;
    justify-content: center;
    background-color: #ffb457;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--duration);

    all: unset;
    flex-grow: 1;
    z-index: 100;
    display: flex;
    cursor: pointer;
    position: relative;
    border-radius: 50%;
    align-items: center;
    will-change: transform;
    justify-content: center;
    padding: 0.55em 0 0.85em;
    transition: transform var(--timeOut , var(--duration));

    content: "";
    z-index: -1;
    width: 4.2em;
    height: 4.2em;
    border-radius: 50%;
    position: absolute;
    transform: scale(1);
    background-color: var(--bgColorItem);

    width: 2.6em;
    height: 2.6em;
    stroke: white;
    fill: transparent;
    stroke-width: 1pt;
    stroke-miterlimit: 10;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 400;
    animation: strok 1.5s infinite;
    animation-direction: reverse;

@keyframes strok {

    100% {

        stroke-dashoffset: 400;



Effect display