Skip to the content

Elastic line

The rules of a page, pulled like strings. Every separator that carries the attribute is caught by the pointer as it comes close or crosses it, bends towards it like a guitar string, slips free once it is pulled too far, and springs back on a damped spring, wobbling until it rests.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    A marked rule takes its height and its background from the settings thickness and color, so a height or a background set on its class is overridden. Its path spills out of its box while it bends: a parent with overflow: hidden close to the rule cuts the bend off.
  3. Add custom JS

  4. Use it on your own elements

    Custom attributes
    Select the element on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-elastic-line Marks a rule the pointer pulls like a string. It takes no value: leave the value field empty. It goes on an empty div that draws the rule, between two rows, under a heading or above a footer; the stylesheet makes that div a box as thick and as dark as the settings say, as wide as its container.
    data-elastic-line-state Written by the engine on the rule: live while the line is bent or moving, idle at rest, still under reduced motion. Never written by hand. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same element. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-elastic-line-color #15100c Colour of the line, at rest and in motion. Options: any CSS colour, currentColor included, which takes the text colour of the rule's parent.
    data-elastic-line-thickness 1 Thickness of the line, in px, the height of the box at rest and the stroke of the path in motion.
    data-elastic-line-bend clamp(24px, 3vw, 44px) How far the pointer can pull the line before it slips free, any CSS unit; it is also the most a line ever bends.
    data-elastic-line-reach clamp(8px, 1vw, 16px) Distance from the line, above and below, at which the pointer catches it without crossing it, any CSS unit.
    data-elastic-line-stiffness 380 Tension of the string, the pull that brings the line back to rest, 20 to 2000.
    data-elastic-line-damping 7 How fast the wobble dies, 1 to 60.
    data-elastic-line-touch 1 Whether a finger pulls the line, 0 or 1. Options: 1 a finger put on a rule holds it and a tap plucks it; 0 touch is ignored and the rules stay straight on a phone.

What it does

Elastic line is a cursor animation for Webflow and vanilla JavaScript, with no library. Also called elastic line hover effect, elastic divider or guitar string line effect.

The rules of a page, pulled like strings. Every separator that carries the attribute is caught by the pointer as it comes close or crosses it, bends towards it like a guitar string, slips free once it is pulled too far, and springs back on a damped spring, wobbling until it rests. A list, a table, a footer: each rule is on its own spring, so a pointer run down a page strums them one after the other. At rest a rule is a plain box one pixel thick, which the browser snaps to whole device pixels, so it is crisp on every screen density and takes the width of its container like any other box; an SVG path of the same colour takes its place only while it moves. No library: a small spring integrator, one set of listeners for the whole page and one frame loop that runs only while a line moves. On touch, a finger put on a rule holds it and lifting lets it go, and a tap plucks it. Under reduced motion the rules stay straight.

Updated

Questions

Put an empty div wherever the page needs a rule and give it the custom attribute data-elastic-line. It is the rule itself, not a border and not an hr: a border-bottom cannot bend, and an hr holds no child for the script to lay its path in. Settings go on the rule, for instance data-elastic-line-color="#ffab1a".

No. The engine is a small spring integrator with no library, one set of listeners for the whole page and one frame loop that runs only while a line moves. At rest a rule is a plain box one pixel thick, and an SVG path of the same colour takes its place only while it bends.

data-elastic-line-bend is how far the pointer can pull the line before it slips free, clamp(24px, 3vw, 44px) by default: lower is a tight string that lets go almost at once, higher a slack one. data-elastic-line-damping, 7 by default, is how fast the wobble dies, and a lower value lets the line ring for seconds. data-elastic-line-stiffness, 380 by default, goes from a loose rope to a nervous wire.

Yes. A finger put within 24px of a rule holds it, lifting lets it go, and a short tap plucks it, all through touch events so the page still scrolls under the finger. Write data-elastic-line-touch="0" and the rules stay straight on a phone.

A line that is cut has an ancestor with overflow: hidden close to it: the path spills out of its box, up to bend above and below. A line that does not react is often 0px wide, which happens to a div with no width in a flex row, so give it flex: 1. Under prefers-reduced-motion the rules stay straight on purpose.