← All elements

Text Roll Button

by @admin · 16 views

<button class="pc-roll" type="button">
  <span class="pc-roll__clip">
    <span class="pc-roll__in" data-text="Add to cart">Add to cart</span>
  </span>
</button>

About this button

A button whose label rolls upward and is replaced by an identical copy on hover, using a data attribute and a clipped pseudo-element.

How it works

The label sits inside a clipping wrapper with overflow: hidden. A pseudo-element prints a copy of the same text, taken from a data-text attribute, directly below it. On hover or focus the label moves up by its own height, so the original rolls out of view and the copy rolls in.

Ways to customise it

  • Change the text in both the label and data-text.
  • Change the cubic-bezier for a snappier or smoother roll.
  • Change #4f35e8 and the 10px radius to match your brand.

Good to know

The copy is hidden from screen readers by the alternative text syntax in the content rule, so the label is not read twice. Keep the text and the data-text attribute in sync when you edit it.

Open an example, copy the HTML and the CSS, and paste them into your page. There is nothing to install and no JavaScript to load.

More in Buttons

View all →