仕組み
The track holds two identical groups; a CSS animation moves it from 0 to -50%, exactly one group, and back seamlessly. Short content is repeated inside each group so there is never a gap. Duration is group length ÷ speed, measured again with a ResizeObserver, so the speed in pixels per second holds for any content; changing it keeps the current progress. Copies are aria-hidden and inert. The fade uses mask-image, so it works on any background.
向いている場面
- Showing partner names, logos or press mentions on a marketing page.
- Decorative areas that rotate many tags in limited space.
- A scrolling announcement strip at the top of a page (vertical).
向かない場面
- Important information people must read or click: moving content is easy to miss.
- More than two on one screen: several moving areas distract.
- Lists that people browse and compare item by item: use plain scrolling or a grid.
使い方
import { Marquee } from './Marquee.jsx'
export function Cities({ cities }) {
return (
<Marquee speed={40} direction="left" pauseOnHover fade>
{cities.map((city) => (
<CityTag key={city.id} city={city} />
))}
</Marquee>
)
}
// Vertical: give it a fixed height
<Marquee direction="up" style={{ height: 160 }}>{notices}</Marquee>プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
speed | number | 40 | Scroll speed in pixels per second, independent of content length. |
direction | 'left' | 'right' | 'up' | 'down' | 'left' | Scroll direction. Vertical needs a fixed height on the component. |
pauseOnHover | boolean | true | Pauses while the pointer is over it. Keyboard focus always pauses. |
fade | boolean | true | Fades both ends with a mask. |
fadeSize | number | 48 | Length of the fade area in px. |
gap | number | 12 | Space between items in px, the same at the loop seam. |
paused | boolean | false | Pauses from outside, for example from a “pause scrolling” button. |
children | ReactNode | — | The scrolling content: a set of elements side by side. |
...rest | HTMLAttributes | — | Other attributes go to the root element, such as className, style and role. |
アクセシビリティ
- Only the first copy is visible to screen readers; the others are aria-hidden and inert, so nothing is read twice or reached by Tab.
- Keyboard focus pauses it automatically, and the paused prop lets you add a pause button (WCAG 2.2.2).
- Hover pause applies only on devices that can hover, so touch never gets stuck paused.
- With reduced motion it does not scroll by itself, copies and fade are removed, and people scroll by hand.
モーション
Constant speed (linear, otherwise each loop would hitch at the seam); duration is group length ÷ speed. Changing speed keeps progress; hover or focus pauses instantly.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
Marquee.jsxmarquee.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。





