Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- svg describing the loader
made up of dashes and the race car
-->
<svg viewBox="0 0 178 40" width="178" height="40">
    <!-- dash included behind the car
    ! be sure to delay the animation of the path after the dashes on the right side of the car
    -->
    <path
        class="air"
        d="M 46 16.5 h -20 a 8 8 0 0 1 0 -16"
        fill="none"
        stroke="#E85725"
        stroke-width="1"
        stroke-linejoin="round"
        stroke-linecap="round">
    </path>

    <!-- wrap the svg describing the car in a group
    this to translate the car horizontally within the wrapping svg
    -->
    <g id="car">
        <!-- svg describing the race car in a container 118 wide and 28.125 tall
        .125 due to the 2.25 width of the stroke

        position in the bottom center of the wrapping svg
        -->
        <svg viewBox="0 0 118 28.125" x="30" y="11.725" width="118" height="28.125">
            <defs>
                <!-- circle repeated for the wheel -->
                <circle
                    id="circle"
                    cx="0"
                    cy="0"
                    r="1">
                </circle>
                <!-- wheel
                three overlapping circles describing the parts of the wheel
                in between the circles add path elements to detail the graphic
                -->
                <g id="wheel">
                    <use href="#circle" fill="#1E191A" transform="scale(10)"></use>
                    <use href="#circle" fill="#fff" transform="scale(5)"></use>
                    <!-- inner shadow -->
                    <path
                        fill="#1E191A"
                        stroke="#1E191A"
                        stroke-width="0.5"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        opacity="0.2"
                        stroke-dashoffset="0"
                        d="M -3.5 0 a 4 4 0 0 1 7 0 a 3.5 3.5 0 0 0 -7 0">
                    </path>
                    <use href="#circle" fill="#1E191A" transform="scale(1.5)"></use>
                    <!-- yellow stripe
                    include stroke-dasharray values totalling the circumference of the circle
                    this to use the dash-offset property and have the stripe rotate around the center while keeping its shape
                    ! explicitly set the stroke-dashoffset property to 0 for the other path elements (in this way the stroke-dashoffset attribute added through the <use> element affects only this path)
                    -->
                    <path
                        fill="none"
                        stroke="#F9B35C"
                        stroke-width="0.75"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        stroke-dasharray="20 14 8 5"
                        d="M 0 -7.5 a 7.5 7.5 0 0 1 0 15 a 7.5 7.5 0 0 1 0 -15">
                    </path>
                    <!-- outer glow (from a hypothetical light source) -->
                    <path
                        fill="none"
                        stroke="#fff"
                        stroke-width="1"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        opacity="0.1"
                        stroke-dashoffset="0"
                        d="M -6.5 -6.25 a 10 10 0 0 1 13 0 a 9 9 0 0 0 -13 0">
                    </path>
                </g>
            </defs>
            <!-- group describing the pilot's helmet
            translate in the middle of the cockpit
            -->
            <g transform="translate(51.5 11.125)">
                <path
                    stroke-width="2"
                    stroke="#1E191A"
                    fill="#EF3F33"
                    d="M 0 0 v -2 a 4.5 4.5 0 0 1 9 0 v 2">
                </path>
                <rect
                    fill="#1E191A"
                    x="3.25"
                    y="-3"
                    width="5"
                    height="3">
                </rect>
            </g>

            <!-- group describing the car -->
            <g transform="translate(10 24.125)">
                <!-- shadow below the car
                ! change the transform-origin of the shadow to animate it from the top center
                the idea is to skew the shadow as the car moves
                -->
                <g transform="translate(59 0)">
                    <path
                        id="shadow"
                        opacity="0.7"
                        fill="#1E191A"
                        d="M -64 0 l -4 4 h 9 l 8 -1.5 h 100 l -3.5 -2.5">
                    </path>
                </g>
                <!-- path describing the frame of the car
                ! do not add a stroke at the bottom of the frame
                additional lines are overlapped to detail the belly of the vehicle
                -->
                <path
                    fill="#fff"
                    stroke="#1E191A"
                    stroke-width="2.25"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M 0 0 v -10 l 35 -13 v 5 l 4 0.5 l 0.5 4.5 h 35.5 l 30 13">
                </path>

                <!-- wings -->
                <g
                    fill="#fff"
                    stroke="#1E191A"
                    stroke-width="2.25"
                    stroke-linecap="round"
                    stroke-linejoin="round">
                    <path
                        d="M -6 0 v -22 h 10 z">
                    </path>
                    <path
                        d="M 105 0 h -3 l -12 -5.2 v 6.2 h 12">
                    </path>
                </g>

                <!-- grey areas to create details around the car's dashes -->
                <g
                    fill="#949699"
                    opacity="0.7">
                    <rect
                        x="16"
                        y="-6"
                        width="55"
                        height="6">
                    </rect>
                    <path
                        d="M 24 -14 l 13 -1.85 v 1.85">
                    </path>
                </g>

                <!-- dashes included sparingly on top of the frame -->
                <g
                    fill="none"
                    stroke="#1E191A"
                    stroke-width="2.25"
                    stroke-linecap="round"
                    stroke-linejoin="round">
                    <path
                        stroke-dasharray="30 7 42"
                        d="M 90 0 h -78">
                    </path>
                    <path
                        d="M 39.5 -13 h -15">
                    </path>
                </g>

                <!-- elements describing the side of the car -->
                <path
                    fill="#fff"
                    stroke="#1E191A"
                    stroke-width="2.25"
                    stroke-linejoin="round"
                    d="M 48.125 -6 h -29 v 6 h 29"><!-- .125 to tuck the path behind the rectangle and avoid a pixel disconnect as the svg is scaled -->
                </path>

                <rect
                    x="48"
                    y="-7.125"
                    width="6.125"
                    height="7.125"
                    fill="#1E191A">
                </rect>

                <!-- rear view mirror -->
                <g fill="#1E191A">
                    <rect
                        x="60"
                        y="-15"
                        width="1"
                        height="6">
                    </rect>
                    <rect
                        x="56.5"
                        y="-17.5"
                        width="6"
                        height="2.5">
                    </rect>
                </g>
            </g>

            <!-- group describing the wheels, positioned at the bottom of the graphic and at either end of the frame -->
            <g class="wheels" transform="translate(0 18.125)">
                <g transform="translate(10 0)">
                    <use href="#wheel"></use>
                </g>

                <g transform="translate(87 0)">
                    <!-- add an offset to rotate the yellow stripe around the center -->
                    <use href="#wheel" stroke-dashoffset="-22"></use>
                </g>
            </g>
        </svg>
    </g>

    <!-- dashes included above and around the race car
    ! include them in order from right to left
    this allows to rapidly assign an increasing delay in the script, to have the dashes animated in sequence
    -->
    <g
        fill="none"
        stroke-width="1"
        stroke-linejoin="round"
        stroke-linecap="round">
        <!-- right side -->
        <path
            class="air"
            stroke="#E85725"
            d="M 177.5 34 h -10 q -16 0 -32 -8">
        </path>

        <path
            class="air"
            stroke="#949699"
            d="M 167 28.5 c -18 -2 -22 -8 -37 -10.75">
        </path>

        <path
            class="air"
            stroke="#949699"
            d="M 153 20 q -4 -1.7 -8 -3">
        </path>

        <path
            class="air"
            stroke="#E85725"
            d="M 117 16.85 c -12 0 -12 16 -24 16 h -8"><!-- around (117 29.85) where the right wheel is centered -->
        </path>

        <!-- left side -->
        <path
            class="air"
            stroke="#949699"
            d="M 65 12 q -5 3 -12 3.8">
        </path>

        <path
            class="air"
            stroke="#949699"
            stroke-dasharray="9 10"
            d="M 30 13.5 h -2.5 q -5 0 -5 -5">
        </path>

        <path
            class="air"
            stroke="#949699"
            d="M 31 33 h -10">
        </path>

        <path
            class="air"
            stroke="#949699"
            d="M 29.5 23 h -12">
        </path>
        <path
            class="air"
            stroke="#949699"
            d="M 13.5 23 h -6">
        </path>

        <path
            class="air"
            stroke="#E85725"
            d="M 28 28 h -27.5">
        </path>
    </g>
</svg>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
body {
  min-height: 100vh;
  background: #403c3c;
  /* center in the viewport */
  display: grid;
  justify-content: center;
  align-content: center;
}
/* on the svg element set up a default value for the --stroke-dash and --stroke-dash-negative attributes
46 roughly being the length of the longest path.air
*/
body > svg {
  width: 600px;
  height: auto;
  --stroke-dash: 46;
  --stroke-dash-negative: -46;
}
/* animate the car to move slightly forwards and backwards */
g#car {
  transform: translateX(-3px);
  animation: translate 2s ease-in-out infinite;
}
/* animate the shadow to skew  toward the left */
path#shadow {
  animation: skew 2s ease-in-out infinite;
}
/* animate the wheels to spin  clockwise*/
g.wheels use {
  animation: rotate 2s linear infinite;
}
/* animate the dashes of air to briefly show them and then hide them from view */
path.air {
  /* starting from the values described by the --stroke-dash property
  ! the property is updated for each path in the script
  */
  stroke-dasharray: var(--stroke-dash);
  stroke-dashoffset: var(--stroke-dash);
  /* ! the delay of the animation is also set up in the script  */
  animation: offset 2s linear infinite;
  /* opacity to hide the obnoxious dots otherwise shown on firefox and edge */
  opacity: 0;
}

/* keyframe animations
! be sure to have the animations overlap as to show a realistic behavior
- as the car moves right the wheels spin faster, the shadow skews left, the dashes of air appear in sequence
- as the car moves left the wheels spin slower while the shadow returns to its resting place
*/
@keyframes translate {
  50% {
    transform: translateX(3px);
  }
  100% {
    transform: translateX(-3px);
  }
}
@keyframes skew {
  50% {
    transform: skewX(-20deg);
  }
}
@keyframes rotate {
  50% {
    transform: rotate(4turn);
  }
  100% {
    transform: rotate(6turn);
  }
}

/* beside animating the stroke-dashoffset property rapidly change the opacity to show the dashes and hide them when they are removed by changing the offset property
otherwise the dashes would still be partially visible on firefox and edge (at least)
*/
@keyframes offset {
  1% {
    opacity: 1;
  }
  15% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
  24% {
    opacity: 1;
  }
  25% {
    opacity: 0;
    /* ! on chrome and firefox the calc() function allows to compute the negative value, but Edge seems to prefer having another variable instead */
    /* stroke-dashoffset: calc(var(--stroke-dash) * -1px); */
    stroke-dashoffset: var(--stroke-dash-negative);
  }
  100% {
    stroke-dashoffset: var(--stroke-dash-negative);
  }
}

              
            
!

JS

              
                // target all path elements describing the gusts of air around the race car
const paths = document.querySelectorAll('path.air');

/*
for each path update the --stroke-dash property to match the length of the stroke
! create another property for the negative offset (mostly due to Edge not liking the calc() function with custom properties)
! include also an increasing delay to animate the path in sequence
*/
// add an increasing delay to the animation
paths.forEach((path, index) => {
  const totalLength = path.getTotalLength();
  path.style.setProperty('--stroke-dash', totalLength);
  path.style.setProperty('--stroke-dash-negative', -totalLength);
  // ! as the first path actually describes a stroke on the left side of the car, tailor its delay to occur with the dashes on the left side
  if (index === 0) {
    path.style.animationDelay = `${0.08 * (paths.length - 2)}s`;
  } else {
    path.style.animationDelay = `${0.08 * index}s`;
  }
});

              
            
!
999px

Console