Marquee for Astro
Astro moving content rows with direction, duration, and spacing controls.
Installation
bunx --bun shadcn@latest add @gnostic/marqueenpx shadcn@latest add @gnostic/marqueepnpm dlx shadcn@latest add @gnostic/marqueeComplete the Installation guide first. Then copy the component files below.
No extra packages are required.
Copy the files
src/components/ui/marquee/index.ts
export { default as Marquee } from "./marquee.astro"
src/components/ui/marquee/marquee.astro
---
import type { HTMLAttributes } from "astro/types"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const trackVariants = cva(
"flex min-w-max shrink-0 [animation:marquee_var(--marquee-duration)_linear_infinite] items-center gap-(--marquee-gap) before:block before:size-0 before:shrink-0 before:content-['']",
{
variants: {
direction: {
left: "",
right: "[animation-direction:reverse]",
},
pauseOnHover: {
true: "group-hover/marquee:[animation-play-state:paused]",
false: "",
},
},
defaultVariants: {
direction: "left",
pauseOnHover: false,
},
},
)
type Props = HTMLAttributes<"div"> &
VariantProps<typeof trackVariants> & {
duration?: string
gap?: string
infinite?: boolean
}
const {
class: className,
direction,
pauseOnHover,
duration = "40s",
gap = "1.5rem",
infinite = true,
style,
...props
} = Astro.props
const resolvedStyle = [
`--marquee-duration:${duration}`,
`--marquee-gap:${gap}`,
typeof style === "string" ? style : undefined,
]
.filter(Boolean)
.join(";")
---
<div
class={cn(
"group/marquee flex overflow-hidden select-none [--marquee-duration:40s] [--marquee-gap:1.5rem]",
className,
)}
style={resolvedStyle}
{...props}
>
<div class={trackVariants({ direction, pauseOnHover })}>
<slot />
</div>
{infinite && (
<div aria-hidden="true" class={trackVariants({ direction, pauseOnHover })}>
<slot />
</div>
)}
</div>
<style>
@keyframes marquee {
from {
transform: translateX(0);
}
to {
transform: translateX(-100%);
}
}
</style>
Usage
import { Marquee } from "@/components/ui/marquee"
<Marquee>
<span>Design systems</span>
<span>Astro</span>
<span>Content sites</span>
</Marquee>
The marquee duplicates its slot by default for a seamless loop.
<Marquee>
<span>Design systems</span>
<span>Astro</span>
<span>Content sites</span>
</Marquee>
Examples
Seamless Loop
Direction
Control the scroll direction with the direction prop.
Pause on Hover
Enable pause on hover with the pauseOnHover prop.
Styling
Set infinite={false} when you only want to render the slot once.
API Reference
Read the installed source for the complete prop types.
When to use Marquee
Use Marquee for secondary visual content such as a short logo sequence. Set direction, duration, and gap through its props. Keep a readable static route to any information that matters.
Keyboard and behavior
Motion must not prevent users from reading or activating content. Use the pause option where appropriate and test reduced-motion preferences. Repeated visual content should not cause repeated announcements or duplicate focus targets.
Theme and layout
Check the loop boundary with the actual content widths. Large gaps and mismatched items can expose an empty region. Colors come from the children, so inspect logos against both theme backgrounds.