GoodMotion

Rubber Band Text

Text 1

About

Interactive elastic typography that stretches and snaps back smoothly on hover or cursor proximity. Explore more free motion components at GoodMotion

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Rubber Band Text to your project and fits it to your theme.

Code

How Rubber Band Text is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import React, { useState, useEffect } from "react";
import RubberBandText from "@/components/ui/rubber-band-text";

export interface ProjectItem {
  id: number;
  title: string;
  category: string;
  image: string;
}

const PROJECTS: ProjectItem[] = [
  {
    id: 1,
    title: "OUTWAY",
    category: "LIFESTYLE",
    image:
      "https://cdn.21st.dev/assets/mirror/50/506275480e1c369fcf99b00ca0b94295e18bb62609e3dd4413af0bd403618501.png",
  },
  {
    id: 2,
    title: "RESTLESS",
    category: "STUDIO",
    image:
      "https://cdn.21st.dev/assets/mirror/ac/ac08179ba69e8e34e33d38ba2a0741cfee046f0984a04026c7fa099917a71890.png",
  },
  {
    id: 3,
    title: "RMC STUDIO",
    category: "CREATIVE",
    image:
      "https://cdn.21st.dev/assets/mirror/47/4775ce8078f180e4a9084d753521fe0642e73ad3d8f7a19e34cb3920ba35287a.png",
  },
  {
    id: 4,
    title: "SCHEMATIK",
    category: "PORTFOLIO",
    image:
      "https://cdn.21st.dev/assets/mirror/35/35aa8e593666280f35ad182547cac1cf2b73c6ee0078667f6e5afda387642499.png",
  },
  {
    id: 5,
    title: "TEXT DISTORTION",
    category: "EXPERIMENT",
    image:
      "https://cdn.21st.dev/assets/mirror/16/166f8528a5607288533dca6ffc6fe1adf1aca201cba80ffad5494565236a908f.jpg",
  },
  {
    id: 6,
    title: "THE NODE",
    category: "DIGITAL AGENCY",
    image:
      "https://cdn.21st.dev/assets/mirror/34/340b89211635696f7856ff67b672f7e72660247fae6c867b6a849e7589968188.png",
  },
  {
    id: 7,
    title: "OUTWAY GEAR",
    category: "COLLECTION",
    image:
      "https://cdn.21st.dev/assets/mirror/50/506275480e1c369fcf99b00ca0b94295e18bb62609e3dd4413af0bd403618501.png",
  },
  {
    id: 8,
    title: "RESTLESS ARCHIVE",
    category: "EDITORIAL",
    image:
      "https://cdn.21st.dev/assets/mirror/ac/ac08179ba69e8e34e33d38ba2a0741cfee046f0984a04026c7fa099917a71890.png",
  },
  {
    id: 9,
    title: "RMC VISUAL",
    category: "BRANDING",
    image:
      "https://cdn.21st.dev/assets/mirror/47/4775ce8078f180e4a9084d753521fe0642e73ad3d8f7a19e34cb3920ba35287a.png",
  },
  {
    id: 10,
    title: "SCHEMATIK LAB",
    category: "INTERFACE",
    image:
      "https://cdn.21st.dev/assets/mirror/35/35aa8e593666280f35ad182547cac1cf2b73c6ee0078667f6e5afda387642499.png",
  },
  {
    id: 11,
    title: "GLITCH DYNAMICS",
    category: "TYPOGRAPHY",
    image:
      "https://cdn.21st.dev/assets/mirror/16/166f8528a5607288533dca6ffc6fe1adf1aca201cba80ffad5494565236a908f.jpg",
  },
  {
    id: 12,
    title: "NODE VENTURES",
    category: "STRATEGY",
    image:
      "https://cdn.21st.dev/assets/mirror/34/340b89211635696f7856ff67b672f7e72660247fae6c867b6a849e7589968188.png",
  },
];

export function RubberBandTextDemo() {
  const [mounted, setMounted] = useState(false);
  // Default desktop width is 1200px
  const [windowWidth, setWindowWidth] = useState(1200);

  useEffect(() => {
    setMounted(true);
    setWindowWidth(window.innerWidth);

    const handleResize = () => setWindowWidth(window.innerWidth);
    window.addEventListener("resize", handleResize);
    return () => window.removeEventListener("resize", handleResize);
  }, []);

  const is1920 = mounted && windowWidth >= 1600;
  const isMobile = mounted && windowWidth < 768;

  // Grid columns resolution:
  // > 1200px: 5 cards
  // 1200px: 4 cards (default)
  // 768px <= x < 1200px: 3 cards
  // < 768px: 1 card
  const columns = !mounted
    ? 4
    : windowWidth > 1200
    ? 5
    : windowWidth === 1200
    ? 4
    : windowWidth >= 768
    ? 3
    : 1;

  // Lấy chính xác số lượng thẻ để luôn lấp đầy đủ 2 hàng ở mọi breakpoint (columns * 2)
  const displayedProjects = PROJECTS.slice(0, columns * 2);

  return (
    <div
      style={{
        backgroundColor: "#FFFFFF",
        color: "#000000",
        minHeight: "100vh",
        width: "100%",
        position: "relative",
        boxSizing: "border-box",
        fontFamily: "'Inter', sans-serif",
        letterSpacing: "-0.06em",
        lineHeight: 1,
        overflowX: "hidden",
        paddingLeft: isMobile ? "16px" : "24px",
        paddingRight: isMobile ? "16px" : "24px",
        paddingTop: "24px",
        paddingBottom: "80px",
      }}
    >
      {/* Import Inter Font */}
      <style>
        {`@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');`}
      </style>

      {/* A. NAVBAR */}
      <nav
        style={{
          width: "100%",
          display: "flex",
          justifyContent: "space-between",
          alignItems: "flex-start",
          boxSizing: "border-box",
          marginBottom: is1920 ? "175px" : "150px", // 175px ở breakpoint 1920, 150px ở các breakpoint còn lại
        }}
      >
        {/* LOGO GECCO */}
        <span
          style={{
            fontFamily: "'Inter', sans-serif",
            fontSize: "24px",
            fontWeight: 800,
            letterSpacing: "-0.06em",
            lineHeight: 1,
            color: "#000000",
            userSelect: "none",
          }}
        >
          GECCO
        </span>

        {/* Tagline ở giữa (Chỉ hiển thị trên Desktop & Tablet, ẩn trên Mobile) */}
        {!isMobile && (
          <p
            style={{
              margin: 0,
              fontFamily: "'Inter', sans-serif",
              fontSize: "16px",
              fontWeight: 500,
              letterSpacing: "-0.06em",
              lineHeight: 1,
              textAlign: "left",
              maxWidth: "340px",
              color: "#000000",
              textTransform: "uppercase",
            }}
          >
            GECCO IS THE OFFICIAL STRATEGY &amp; CREATIVE CO-CREATION
            DEVELOPMENT PARTNER
          </p>
        )}

        {/* Nút Contact us */}
        <button
          type="button"
          style={{
            fontFamily: "'Inter', sans-serif",
            fontSize: "16px",
            fontWeight: 500,
            letterSpacing: "-0.06em",
            lineHeight: 1,
            color: "#000000",
            textTransform: "uppercase",
            background: "none",
            border: "none",
            padding: 0,
            margin: 0,
            cursor: "pointer",
            transition: "opacity 0.2s ease",
          }}
          onMouseEnter={(e) => (e.currentTarget.style.opacity = "0.6")}
          onMouseLeave={(e) => (e.currentTarget.style.opacity = "1")}
        >
          CONTACT US
        </button>
      </nav>

      {/* B. Hero Typography ("GECCO" Kinetic Stretch Text) */}
      <section
        style={{
          width: "100%",
          display: "block",
          boxSizing: "border-box",
        }}
      >
        <RubberBandText
          text="GECCO"
          fontFamily="'Inter', sans-serif"
          fontWeight={400}
          textColor="#000000"
          backgroundColor="transparent"
          extremeCompression={1.15}
          waveCycles={1.35}
          autoPlay={true}
          flowSpeed={1}
          mouseInfluence={0.85}
        />
      </section>

      {/* C. Lưới Thẻ Dự Án (Showcase Card Grid) */}
      {/* card item cách Hero Typography 16px */}
      <section
        style={{
          marginTop: "16px",
          width: "100%",
          display: "grid",
          gridTemplateColumns: `repeat(${columns}, 1fr)`,
          columnGap: "8px", // thẻ trái cách thẻ phải 8px
          rowGap: "16px", // thẻ trên cách thẻ dưới 16px
          boxSizing: "border-box",
        }}
      >
        {displayedProjects.map((item) => (
          <article
            key={item.id}
            style={{
              display: "flex",
              flexDirection: "column",
              width: "100%",
              boxSizing: "border-box",
            }}
          >
            {/* Thumbnail tỉ lệ 16:9, không border, không bo góc (vuông vức) */}
            {/* thumbnail cách tên dự án 4px */}
            <div
              style={{
                width: "100%",
                aspectRatio: "16 / 9",
                overflow: "hidden",
                marginBottom: "4px",
                backgroundColor: "#E5E5E5",
              }}
            >
              <img
                src={item.image}
                alt={item.title}
                loading="lazy"
                style={{
                  width: "100%",
                  height: "100%",
                  objectFit: "cover",
                  display: "block",
                  borderRadius: 0,
                  border: "none",
                }}
              />
            </div>

            {/* Tên dự án: 16px, 600, black 100%, cách chuyên mục 2px */}
            <h3
              style={{
                margin: "0 0 2px 0",
                fontFamily: "'Inter', sans-serif",
                fontSize: "16px",
                fontWeight: 600,
                color: "#000000",
                letterSpacing: "-0.06em",
                lineHeight: 1,
              }}
            >
              {item.title}
            </h3>

            {/* Tên chuyên mục: 16px, 600, black 50% */}
            <p
              style={{
                margin: 0,
                fontFamily: "'Inter', sans-serif",
                fontSize: "16px",
                fontWeight: 600,
                color: "rgba(0, 0, 0, 0.5)",
                letterSpacing: "-0.06em",
                lineHeight: 1,
              }}
            >
              {item.category}
            </p>
          </article>
        ))}
      </section>
    </div>
  );
}

export default RubberBandTextDemo;

Dependencies

More by GoodMotion

View all
  • Googly Eye Cursor

    Googly Eye Cursor

    26
  • Circle Reveal Loader

    Circle Reveal Loader

    24
  • Y2K Dreamy Text

    Y2K Dreamy Text

    9
  • X-Ray Figma Cursor

    X-Ray Figma Cursor

More in Text

View all
  • Vertical Cut Reveal Characters

    Vertical Cut Reveal Characters

    130
  • Motion Blur Text

    Motion Blur Text

    43
  • Rainbow Text Effect

    Rainbow Text Effect

    56
  • Text Reveal

    Text Reveal

    39
  • Blur Reveal

    Blur Reveal

    351
  • Text Highlight

    Text Highlight

    91
  • Apple Hello Effect

    Apple Hello Effect

    654
  • Highlight Text

    Highlight Text

    166