Floating 3D Particles
Install: npx shadcn@latest add https://jiguang132.com/r/magic-ui/floating-3d-particles.json
Use case
Render depth-scaled floating particles on Canvas.
Native props used by the examples
Extracted from all local examples for this entry, grouped by imported module and native owner, including other Magic components used by compound demos. This is not an exhaustive API or a universal host variant. Inspect spread object declarations and the source types/defaults below.
| Owning component prop | Explanation | Example source |
|---|---|---|
Floating3DParticles.color (floating-3d-particles) | The owning effect's native color; preserve any restricted color format. | examples/floating-3d-particles-demo.tsx、examples/floating-3d-particles-demo-2.tsx |
Floating3DParticles.depth (floating-3d-particles) | Simulated particle perspective intensity from 0 to 1. | examples/floating-3d-particles-demo-2.tsx |
Floating3DParticles.opacity (floating-3d-particles) | Native effect opacity; normally a 0–1 fraction. | examples/floating-3d-particles-demo-2.tsx |
Floating3DParticles.quantity (floating-3d-particles) | Particle count and therefore a rendering-workload control. | examples/floating-3d-particles-demo-2.tsx |
Interaction and state checks
- Floating 3D Particles Demo —
floating-3d-particles-demo - Floating 3D Particles Demo 2 —
floating-3d-particles-demo-2
These names identify real example entries, not new component props or extra components. Check pointer/keyboard behavior, themes, small screens and failures for the selected example. Decorative effects must not invent disabled/error/submission states. Complete example installation includes the actual dependency closure.
Business integration boundary
depth is simulated perspective, not a Three.js scene. quantity affects graphics workload; provide a Canvas failure fallback.
Host and motion setup
Initialize Tailwind CSS v4, semantic CSS variables and the dark variant; import the independent local Registry namespace. Reuse an existing next-themes Provider without substituting JGuang UI/Base UI/HeroUI APIs. Mount effects in view and unmount offscreen; provide static alternatives for unavailable Canvas/WebGL or failed remote media. Respect prefers-reduced-motion and verify timer/RAF/observer/listener cleanup: stopping CSS alone does not prove the engine stopped. Examples provide no backend, login, payment or real AI stream. This practical guide is bilingual; detailed upstream references and demo text retain their original language.
Available examples
floating-3d-particles-demo, floating-3d-particles-demo-2
Demo state and mock data do not provide a backend service. Inspect the component props before wiring real data.
Installation
<Tabs defaultValue="cli"> <TabsList> <TabsTrigger value="cli">CLI</TabsTrigger> <TabsTrigger value="manual">Manual</TabsTrigger> </TabsList> <TabsContent value="cli">npx shadcn@latest add @magicui/floating-3d-particles
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </Tabs>Examples
Plain Background
Usage
Floating3DParticles renders an absolutely positioned canvas (inset-0, pointer-events-none). Place it inside a relative container and layer any foreground content above it with z-10.
import { Floating3DParticles } from "@/components/ui/floating-3d-particles"
<div className="relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border">
<Floating3DParticles color="#8B5CF6" quantity={400} />
<div className="relative z-10 text-center">
<h2 className="text-3xl font-bold">Build Something Magical</h2>
</div>
</div>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the canvas element. |
quantity | number | 400 | Number of particles on desktop viewports. Automatically scales down to 20% on mobile screens (< 768px). |
color | string | "#8B5CF6" | Particle color (supports 3-digit or 6-digit hex). |
size | number | 5 | Mean particle radius in px. Each particle varies within ±40% of this value. |
opacity | number | 0.3 | Mean particle opacity (0–1). Each particle varies within ±0.2, clamped to [0, 1]. |
drift | number | 0.8 | Vertical floating speed in px per frame. Positive drifts upward, negative downward. |
depth | number | 0.5 | 3D depth intensity (0–1). 0 = flat 2D plane; 1 = strong perspective with pronounced near/far scaling. |
Complete example installation
The component command installs the component. Each example command also includes its actual imported components, native support UI, utilities and pinned dependencies. Helpers are not additional catalog components.
Floating 3D Particles Demo
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/floating-3d-particles/floating-3d-particles-demo.json
Default import: @/components/magicui/examples/floating-3d-particles-demo
Dependencies: clsx@2.1.1, lucide-react@1.24.0, next-themes@0.4.6, tailwind-merge@3.6.0
Floating 3D Particles Demo 2
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/floating-3d-particles/floating-3d-particles-demo-2.json
Default import: @/components/magicui/examples/floating-3d-particles-demo-2
Dependencies: clsx@2.1.1, next-themes@0.4.6, tailwind-merge@3.6.0
Minimal usage and theme
import Demo from '@/components/magicui/examples/floating-3d-particles-demo';
import { ThemeProvider } from 'next-themes';
export default function Example() {
return <ThemeProvider attribute="class" defaultTheme="system" enableSystem><Demo /></ThemeProvider>;
}
Initialize Tailwind CSS v4, semantic color variables and the dark variant first. Reuse an existing next-themes provider rather than nesting another. Next Link examples require a Next.js environment; in static Vite projects adapt the demo links to your router without changing the native component API. Some media and tweets require network access. Examples do not supply authentication or backend services.
Source-backed parameter reference
Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.
Floating3DParticles({
quantity = 400,
color = "#8B5CF6",
size = 5,
opacity = 0.3,
drift = 0.8,
depth = 0.5,
className,
style,
...canvasProps
}: Floating3DParticlesProps)
export interface Floating3DParticlesProps extends Omit<
React.CanvasHTMLAttributes<HTMLCanvasElement>,
"width" | "height"
> {
/**
* Number of particles rendered on desktop viewports.
* On mobile screens (< 768px), particle count automatically scales down
* to 20 % to preserve smooth frame rates.
* @default 400
*/
quantity?: number
/**
* Particle color — 3 or 6 digit hex string.
* @default "#8B5CF6"
*/
color?: string
/**
* Mean particle radius in px. Each particle is randomly assigned a size
* within ±40 % of this value.
* @default 5
*/
size?: number
/**
* Mean particle opacity (0–1). Each particle randomly varies within
* ±0.2 of this value, clamped to [0, 1].
* @default 0.3
*/
opacity?: number
/**
* Vertical floating speed in px per frame. Positive values drift upward,
* negative values downward.
* @default 0.8
*/
drift?: number
/**
* 3-D depth intensity on a 0–1 scale. `0` produces a flat 2D plane; `1`
* creates strong perspective with pronounced near/far scaling.
* @default 0.5
*/
depth?: number
}
Destructuring defaults in source
Only defaults written directly in parameter/props destructuring are listed. Conditional expressions, runtime theme and computed values require source inspection; this is not an exhaustive behavior-default list.
// Floating3DParticles
quantity = 400
// Floating3DParticles
color = "#8B5CF6"
// Floating3DParticles
size = 5
// Floating3DParticles
opacity = 0.3
// Floating3DParticles
drift = 0.8
// Floating3DParticles
depth = 0.5
Native and external types
External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.
Omit<
React.CanvasHTMLAttributes<HTMLCanvasElement>,
"width" | "height"
>
React.CanvasHTMLAttributes<HTMLCanvasElement>
HTMLCanvasElement