Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Magnet

    Wrapper that pulls its content toward a nearby mouse, or pushes it away, then springs back. Inner layers can travel further for depth.

    Ready when you are

    Free for small teams. Upgrade when you grow.

    Ready when you are

    Free for small teams. Upgrade when you grow.

    Ready when you are

    Free for small teams. Upgrade when you grow.

    Ready when you are

    Free for small teams. Upgrade when you grow.

    Ready when you are

    Free for small teams. Upgrade when you grow.

    @php
        $section = 'grid place-items-center gap-5 rounded-xl border border-line bg-surface px-6 py-12 text-center';
        $title = 'text-2xl font-semibold text-ink';
        $text = 'mt-2 text-sm text-muted';
        $icon = 'size-5';
    @endphp
    
        <section class="{{ $section }}">
          <div>
            <p class="{{ $title }}">Ready when you are</p>
            <p class="{{ $text }}">Free for small teams. Upgrade when you grow.</p>
          </div>
          <x-markas.magnet>
            <x-markas.button size="lg">Get started <span data-depth="0.5"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="{{ $icon }}"><path d="M5 12h14"></path><path d="m13 6 6 6-6 6"></path></svg></span></x-markas.button>
          </x-markas.magnet>
        </section>
    import { Magnet } from "@/components/markas/Magnet";
    import { Button } from "@/components/markas/Button";
    
    const section =
      "grid place-items-center gap-5 rounded-xl border border-line bg-surface px-6 py-12 text-center";
    const title = "text-2xl font-semibold text-ink";
    const text = "mt-2 text-sm text-muted";
    const icon = "size-5";
    
    export default function MagnetExample() {
      return (
        <section className={section}>
          <div>
            <p className={title}>Ready when you are</p>
            <p className={text}>Free for small teams. Upgrade when you grow.</p>
          </div>
          <Magnet>
            <Button size="lg">
              Get started{" "}
              <span data-depth="0.5">
                <svg
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  aria-hidden="true"
                  className={icon}
                >
                  <path d="M5 12h14"></path>
                  <path d="m13 6 6 6-6 6"></path>
                </svg>
              </span>
            </Button>
          </Magnet>
        </section>
      );
    }
    <script setup lang="ts">
    import Magnet from "@/components/markas/Magnet.vue";
    import Button from "@/components/markas/Button.vue";
    
    const section =
      "grid place-items-center gap-5 rounded-xl border border-line bg-surface px-6 py-12 text-center";
    const title = "text-2xl font-semibold text-ink";
    const text = "mt-2 text-sm text-muted";
    const icon = "size-5";
    </script>
    
    <template>
      <section :class="section">
        <div>
          <p :class="title">Ready when you are</p>
          <p :class="text">Free for small teams. Upgrade when you grow.</p>
        </div>
        <Magnet>
          <Button size="lg"
            >Get started
            <span data-depth="0.5"
              ><svg
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.5"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
                :class="icon"
              >
                <path d="M5 12h14"></path>
                <path d="m13 6 6 6-6 6"></path></svg></span
          ></Button>
        </Magnet>
      </section>
    </template>
    <script lang="ts">
      import Magnet from "$lib/components/markas/Magnet.svelte";
      import Button from "$lib/components/markas/Button.svelte";
    
      const section =
        "grid place-items-center gap-5 rounded-xl border border-line bg-surface px-6 py-12 text-center";
      const title = "text-2xl font-semibold text-ink";
      const text = "mt-2 text-sm text-muted";
      const icon = "size-5";
    </script>
    
    <section class={section}>
      <div>
        <p class={title}>Ready when you are</p>
        <p class={text}>Free for small teams. Upgrade when you grow.</p>
      </div>
      <Magnet>
        <Button size="lg"
          >Get started
          <span data-depth="0.5"
            ><svg
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="1.5"
              stroke-linecap="round"
              stroke-linejoin="round"
              aria-hidden="true"
              class={icon}
            >
              <path d="M5 12h14"></path>
              <path d="m13 6 6 6-6 6"></path></svg
            ></span
          ></Button
        >
      </Magnet>
    </section>
    ---
    import Magnet from "@/components/markas/Magnet.astro";
    import Button from "@/components/markas/Button.astro";
    
    const section =
      "grid place-items-center gap-5 rounded-xl border border-line bg-surface px-6 py-12 text-center";
    const title = "text-2xl font-semibold text-ink";
    const text = "mt-2 text-sm text-muted";
    const icon = "size-5";
    ---
    
      <section class={section}>
        <div>
          <p class={title}>Ready when you are</p>
          <p class={text}>Free for small teams. Upgrade when you grow.</p>
        </div>
        <Magnet>
          <Button size="lg">Get started
            <span data-depth="0.5"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class={icon}>
                <path d="M5 12h14"></path>
                <path d="m13 6 6 6-6 6"></path></svg></span></Button>
        </Magnet>
      </section>
    import { Component } from "@angular/core";
    import { Magnet } from "./markas/magnet.component";
    import { Button } from "./markas/button.component";
    
    @Component({
      selector: "markas-example",
      imports: [Magnet, Button],
      template: `
        <section [class]="section">
          <div>
            <p [class]="title">Ready when you are</p>
            <p [class]="text">Free for small teams. Upgrade when you grow.</p>
          </div>
          <markas-magnet>
            <button markas-button size="lg">
              Get started
              <span data-depth="0.5"
                ><svg
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.5"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  aria-hidden="true"
                  [class]="icon"
                >
                  <path d="M5 12h14"></path>
                  <path d="m13 6 6 6-6 6"></path></svg
              ></span>
            </button>
          </markas-magnet>
        </section>
      `,
    })
    export default class MagnetExample {
      protected readonly section =
        "grid place-items-center gap-5 rounded-xl border border-line bg-surface px-6 py-12 text-center";
      protected readonly title = "text-2xl font-semibold text-ink";
      protected readonly text = "mt-2 text-sm text-muted";
      protected readonly icon = "size-5";
    }

    Examples

    Magnetic social icons in a footer

    Follow MarkasUI

    Follow MarkasUI

    Follow MarkasUI

    Follow MarkasUI

    Follow MarkasUI

    Navbar links with a stronger main action

    Voucher that dodges the pointer

    Catch the voucher if you can

    Rp 50.000 off

    Catch the voucher if you can

    Rp 50.000 off

    Catch the voucher if you can

    Rp 50.000 off

    Catch the voucher if you can

    Rp 50.000 off

    Catch the voucher if you can

    Rp 50.000 off

    Installation

    npx markasui@latest add magnet

    Usage

    <x-markas.magnet>
        <x-markas.button size="lg">
            Get started <span data-depth="0.5">&rarr;</span>
        </x-markas.button>
    </x-markas.magnet>

    Needs Alpine.js.

    import { Magnet } from "@/components/markas/Magnet";
    
    <Magnet strength={0.5} radius={32}>
      <a
        href="/contact"
        aria-label="Email"
        className="grid size-10 place-items-center rounded-full border border-line"
      >
        ...
      </a>
    </Magnet>;
    <template>
      <Magnet
        mode="repel"
        :strength="0.6"
        :radius="70"
        class="rounded-lg border-2 border-dashed px-4 py-2"
      >
        Rp 50.000 off
      </Magnet>
    </template>
    <script lang="ts">
      import Button from "$lib/components/markas/Button.svelte";
      import Magnet from "$lib/components/markas/Magnet.svelte";
    </script>
    
    <Magnet>
      <Button size="lg">Get started <span data-depth="0.5">&rarr;</span></Button>
    </Magnet>
    ---
    import Button from "@/components/markas/Button.astro";
    import Magnet from "@/components/markas/Magnet.astro";
    ---
    
    <Magnet>
      <Button size="lg">Get started <span data-depth="0.5">&rarr;</span></Button>
    </Magnet>

    A small bundled script runs each magnet through the markas-magnet element.

    import { Component } from "@angular/core";
    import { Button } from "./markas/button.component";
    import { Magnet } from "./markas/magnet.component";
    
    @Component({
      selector: "app-cta",
      imports: [Button, Magnet],
      template: `
        <markas-magnet [strength]="0.5" [radius]="32">
          <button markas-button size="lg">
            Get started <span data-depth="0.5">&rarr;</span>
          </button>
        </markas-magnet>
      `,
    })
    export class Cta {}
    • Within radius px of its edges the content follows the mouse by strength (0 to 1) and springs back with a slight overshoot when the mouse moves away.
    • mode="repel" dodges the pointer instead. Keep it for playful, decorative elements.
    • Inner elements with data-depth="0.5" travel 50% further, which makes an arrow or icon inside a button feel layered.
    • The wrapper is w-fit; attributes and class go to it. It listens only while on screen, ignores touch, and stays still with reduced motion.

    Props

    NameTypeDefaultDescription
    strengthnumber0.35Share of the pointer distance the content follows, from 0 to 1. For repel it sets how far the content is pushed, as a share of radius.
    radiusnumber80Distance in px beyond the content edges where the pull starts. It grows smoothly as the pointer comes closer.
    mode"attract" | "repel""attract"Move toward the pointer, or dodge away from it.
    children / slotReactNode / slot-The content, usually one button, link, or icon. Inner elements with data-depth="0.5" travel that much further, such as the arrow in a button.

    Accessibility

    • The pull is visual only; the button or link inside keeps its role, name, and position in the tab order.
    • Keyboard focus inside lifts the content slightly so the focus is easy to follow.
    • Touch input is ignored, and with reduced motion the content stays still.

    Related components

    More markasui components with the same classes in every framework.