PRACTICAL WEB TIP
Dual-Line Text Flip
One line of lettering slides out as an identical line rises into place, creating a seamless text swap.
Live Demo
Hover over the element or use Tab to focus.
Source Code
Copy the HTML, CSS or JavaScript you need for your project.
HTML
<button class="tbx-1015" type="button"><span class="tbx-1015__window"><span class="tbx-1015__line">View our work</span><span class="tbx-1015__line" aria-hidden="true">View our work</span></span></button>
CSS
.tbx-1015{border:0;background:transparent;padding:8px 5px;color:#16344c;font:750 17px/1.45 system-ui,sans-serif;cursor:pointer}
.tbx-1015__window{display:block;position:relative;height:1.45em;overflow:hidden}
.tbx-1015__line{display:block;white-space:nowrap;transition:transform .32s cubic-bezier(.2,.8,.2,1)}
.tbx-1015__line:last-child{color:#267ba0}
.tbx-1015:is(:hover,:focus-visible) .tbx-1015__line{transform:translateY(-100%)}
.tbx-1015:focus-visible{outline:3px solid #7b65db;outline-offset:5px;border-radius:3px}
@media(prefers-reduced-motion:reduce){.tbx-1015__line{transition:none}}
How to Use
Insert the HTML and add the CSS to your stylesheet. Adjust colors and sizes and avoid class conflicts.
Use Case
Useful for navigation menus and portfolio galleries.
Technical Notes
Keep controls usable on touch devices. Test keyboard focus and reduced-motion preferences.
Mobile:Ensure the interactive content remains accessible without hover on touch devices.
Browser:Uses modern CSS. Check behavior in the browsers you support.
Reduced Motion:Check that prefers-reduced-motion is respected.