Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Drag Elements

    Area of cards or stickers you can drag around with light momentum, kept inside its bounds. Arrow keys move a focused item, Escape puts it back.

    Brand refresh

    Warm, calm, a little playful

    Kopi susu New Batik pattern

    Brand refresh

    Warm, calm, a little playful

    Kopi susuNewBatik pattern

    Brand refresh

    Warm, calm, a little playful

    Kopi susuNewBatik pattern

    Brand refresh

    Warm, calm, a little playful

    Kopi susu New Batik pattern

    Brand refresh

    Warm, calm, a little playful

    Kopi susuNewBatik pattern
    @php
        $board = 'h-80 rounded-xl border border-line bg-subtle';
        $note = 'w-44 rounded-lg bg-surface p-4 shadow-overlay';
        $noteTitle = 'text-sm font-semibold text-ink';
        $noteText = 'mt-1 text-sm text-muted';
        $sticker = 'rounded-full bg-primary px-4 py-2 text-sm font-semibold text-on-primary';
        $round = 'grid size-16 place-items-center rounded-full border-2 border-dashed border-success bg-surface text-sm font-semibold text-ink';
        $swatches = 'flex gap-1.5 rounded-lg bg-surface p-2 shadow-overlay';
        $swatchPrimary = 'size-8 rounded-md bg-primary';
        $swatchSuccess = 'size-8 rounded-md bg-success';
        $swatchWarning = 'size-8 rounded-md bg-warning';
        $tag = 'rounded-md border border-line bg-surface px-3 py-1.5 text-sm font-medium text-ink';
    @endphp
    
        <x-markas.drag-elements :seed="4" :class="$board" role="group" aria-label="Moodboard">
          <div class="{{ $note }}">
            <p class="{{ $noteTitle }}">Brand refresh</p>
            <p class="{{ $noteText }}">Warm, calm, a little playful</p>
          </div>
          <span class="{{ $sticker }}">Kopi susu</span>
          <span class="{{ $round }}">New</span>
          <span class="{{ $tag }}">Batik pattern</span>
          <div class="{{ $swatches }}" aria-label="Palette" role="img">
            <span class="{{ $swatchPrimary }}"></span>
            <span class="{{ $swatchSuccess }}"></span>
            <span class="{{ $swatchWarning }}"></span>
          </div>
        </x-markas.drag-elements>
    import { DragElements } from "@/components/markas/DragElements";
    
    const board = "h-80 rounded-xl border border-line bg-subtle";
    const note = "w-44 rounded-lg bg-surface p-4 shadow-overlay";
    const noteTitle = "text-sm font-semibold text-ink";
    const noteText = "mt-1 text-sm text-muted";
    const sticker =
      "rounded-full bg-primary px-4 py-2 text-sm font-semibold text-on-primary";
    const round =
      "grid size-16 place-items-center rounded-full border-2 border-dashed border-success bg-surface text-sm font-semibold text-ink";
    const swatches = "flex gap-1.5 rounded-lg bg-surface p-2 shadow-overlay";
    const swatchPrimary = "size-8 rounded-md bg-primary";
    const swatchSuccess = "size-8 rounded-md bg-success";
    const swatchWarning = "size-8 rounded-md bg-warning";
    const tag =
      "rounded-md border border-line bg-surface px-3 py-1.5 text-sm font-medium text-ink";
    
    export default function DragElementsExample() {
      return (
        <DragElements
          seed={4}
          className={board}
          role="group"
          aria-label="Moodboard"
        >
          <div className={note}>
            <p className={noteTitle}>Brand refresh</p>
            <p className={noteText}>Warm, calm, a little playful</p>
          </div>
          <span className={sticker}>Kopi susu</span>
          <span className={round}>New</span>
          <span className={tag}>Batik pattern</span>
          <div className={swatches} aria-label="Palette" role="img">
            <span className={swatchPrimary}></span>
            <span className={swatchSuccess}></span>
            <span className={swatchWarning}></span>
          </div>
        </DragElements>
      );
    }
    <script setup lang="ts">
    import DragElements from "@/components/markas/DragElements.vue";
    
    const board = "h-80 rounded-xl border border-line bg-subtle";
    const note = "w-44 rounded-lg bg-surface p-4 shadow-overlay";
    const noteTitle = "text-sm font-semibold text-ink";
    const noteText = "mt-1 text-sm text-muted";
    const sticker =
      "rounded-full bg-primary px-4 py-2 text-sm font-semibold text-on-primary";
    const round =
      "grid size-16 place-items-center rounded-full border-2 border-dashed border-success bg-surface text-sm font-semibold text-ink";
    const swatches = "flex gap-1.5 rounded-lg bg-surface p-2 shadow-overlay";
    const swatchPrimary = "size-8 rounded-md bg-primary";
    const swatchSuccess = "size-8 rounded-md bg-success";
    const swatchWarning = "size-8 rounded-md bg-warning";
    const tag =
      "rounded-md border border-line bg-surface px-3 py-1.5 text-sm font-medium text-ink";
    </script>
    
    <template>
      <DragElements :seed="4" :class="board" role="group" aria-label="Moodboard">
        <div :class="note">
          <p :class="noteTitle">Brand refresh</p>
          <p :class="noteText">Warm, calm, a little playful</p>
        </div>
        <span :class="sticker">Kopi susu</span>
        <span :class="round">New</span>
        <span :class="tag">Batik pattern</span>
        <div :class="swatches" aria-label="Palette" role="img">
          <span :class="swatchPrimary"></span>
          <span :class="swatchSuccess"></span>
          <span :class="swatchWarning"></span>
        </div>
      </DragElements>
    </template>
    <script lang="ts">
      import DragElements from "$lib/components/markas/DragElements.svelte";
    
      const board = "h-80 rounded-xl border border-line bg-subtle";
      const note = "w-44 rounded-lg bg-surface p-4 shadow-overlay";
      const noteTitle = "text-sm font-semibold text-ink";
      const noteText = "mt-1 text-sm text-muted";
      const sticker =
        "rounded-full bg-primary px-4 py-2 text-sm font-semibold text-on-primary";
      const round =
        "grid size-16 place-items-center rounded-full border-2 border-dashed border-success bg-surface text-sm font-semibold text-ink";
      const swatches = "flex gap-1.5 rounded-lg bg-surface p-2 shadow-overlay";
      const swatchPrimary = "size-8 rounded-md bg-primary";
      const swatchSuccess = "size-8 rounded-md bg-success";
      const swatchWarning = "size-8 rounded-md bg-warning";
      const tag =
        "rounded-md border border-line bg-surface px-3 py-1.5 text-sm font-medium text-ink";
    </script>
    
    <DragElements seed={4} class={board} role="group" aria-label="Moodboard">
      <div class={note}>
        <p class={noteTitle}>Brand refresh</p>
        <p class={noteText}>Warm, calm, a little playful</p>
      </div>
      <span class={sticker}>Kopi susu</span>
      <span class={round}>New</span>
      <span class={tag}>Batik pattern</span>
      <div class={swatches} aria-label="Palette" role="img">
        <span class={swatchPrimary}></span>
        <span class={swatchSuccess}></span>
        <span class={swatchWarning}></span>
      </div>
    </DragElements>
    ---
    import DragElements from "@/components/markas/DragElements.astro";
    
    const board = "h-80 rounded-xl border border-line bg-subtle";
    const note = "w-44 rounded-lg bg-surface p-4 shadow-overlay";
    const noteTitle = "text-sm font-semibold text-ink";
    const noteText = "mt-1 text-sm text-muted";
    const sticker =
        "rounded-full bg-primary px-4 py-2 text-sm font-semibold text-on-primary";
    const round =
        "grid size-16 place-items-center rounded-full border-2 border-dashed border-success bg-surface text-sm font-semibold text-ink";
    const swatches = "flex gap-1.5 rounded-lg bg-surface p-2 shadow-overlay";
    const swatchPrimary = "size-8 rounded-md bg-primary";
    const swatchSuccess = "size-8 rounded-md bg-success";
    const swatchWarning = "size-8 rounded-md bg-warning";
    const tag =
        "rounded-md border border-line bg-surface px-3 py-1.5 text-sm font-medium text-ink";
    ---
    
    <DragElements seed={4} class={board} role="group" aria-label="Moodboard">
      <div class={note}>
        <p class={noteTitle}>Brand refresh</p>
        <p class={noteText}>Warm, calm, a little playful</p>
      </div>
      <span class={sticker}>Kopi susu</span>
      <span class={round}>New</span>
      <span class={tag}>Batik pattern</span>
      <div class={swatches} aria-label="Palette" role="img">
        <span class={swatchPrimary}></span>
        <span class={swatchSuccess}></span>
        <span class={swatchWarning}></span>
      </div>
    </DragElements>
    import { Component } from "@angular/core";
    import { DragElements } from "./markas/drag-elements.component";
    
    @Component({
      selector: "markas-example",
      imports: [DragElements],
      template: `
        <markas-drag-elements
          [seed]="4"
          [class]="board"
          role="group"
          aria-label="Moodboard"
        >
          <div [class]="note">
            <p [class]="noteTitle">Brand refresh</p>
            <p [class]="noteText">Warm, calm, a little playful</p>
          </div>
          <span [class]="sticker">Kopi susu</span>
          <span [class]="round">New</span>
          <span [class]="tag">Batik pattern</span>
          <div [class]="swatches" aria-label="Palette" role="img">
            <span [class]="swatchPrimary"></span>
            <span [class]="swatchSuccess"></span>
            <span [class]="swatchWarning"></span>
          </div>
        </markas-drag-elements>
      `,
    })
    export default class DragElementsExample {
      protected readonly board = "h-80 rounded-xl border border-line bg-subtle";
      protected readonly note = "w-44 rounded-lg bg-surface p-4 shadow-overlay";
      protected readonly noteTitle = "text-sm font-semibold text-ink";
      protected readonly noteText = "mt-1 text-sm text-muted";
      protected readonly sticker =
        "rounded-full bg-primary px-4 py-2 text-sm font-semibold text-on-primary";
      protected readonly round =
        "grid size-16 place-items-center rounded-full border-2 border-dashed border-success bg-surface text-sm font-semibold text-ink";
      protected readonly swatches =
        "flex gap-1.5 rounded-lg bg-surface p-2 shadow-overlay";
      protected readonly swatchPrimary = "size-8 rounded-md bg-primary";
      protected readonly swatchSuccess = "size-8 rounded-md bg-success";
      protected readonly swatchWarning = "size-8 rounded-md bg-warning";
      protected readonly tag =
        "rounded-md border border-line bg-surface px-3 py-1.5 text-sm font-medium text-ink";
    }

    Examples

    Team cards placed with data-x and data-y

    Rania PutriDesign lead
    Bima SaputraEngineering
    Sekar AyuProduct
    Dimas PratamaResearch
    Rania PutriDesign lead
    Bima SaputraEngineering
    Sekar AyuProduct
    Dimas PratamaResearch
    Rania PutriDesign lead
    Bima SaputraEngineering
    Sekar AyuProduct
    Dimas PratamaResearch
    Rania Putri Design lead
    Bima Saputra Engineering
    Sekar Ayu Product
    Dimas Pratama Research
    Rania PutriDesign lead
    Bima SaputraEngineering
    Sekar AyuProduct
    Dimas PratamaResearch

    Elastic tags that spring back

    Stack we love

    Pull a tag, it springs back

    Laravel Vue React Tailwind CSS Alpine.js Figma

    Stack we love

    Pull a tag, it springs back

    LaravelVueReactTailwind CSSAlpine.jsFigma

    Stack we love

    Pull a tag, it springs back

    LaravelVueReactTailwind CSSAlpine.jsFigma

    Stack we love

    Pull a tag, it springs back

    Laravel Vue React Tailwind CSS Alpine.js Figma

    Stack we love

    Pull a tag, it springs back

    LaravelVueReactTailwind CSSAlpine.jsFigma

    Plans in Rupiah to drag side by side

    Basic

    Rp 49.000

    per month

    Pro

    Rp 99.000

    per month

    Team

    Rp 199.000

    per month

    Basic

    Rp 49.000

    per month

    Pro

    Rp 99.000

    per month

    Team

    Rp 199.000

    per month

    Basic

    Rp 49.000

    per month

    Pro

    Rp 99.000

    per month

    Team

    Rp 199.000

    per month

    Basic

    Rp 49.000

    per month

    Pro

    Rp 99.000

    per month

    Team

    Rp 199.000

    per month

    Basic

    Rp 49.000

    per month

    Pro

    Rp 99.000

    per month

    Team

    Rp 199.000

    per month

    Installation

    npx markasui@latest add drag-elements

    Usage

    <x-markas.drag-elements :seed="4" class="h-80 rounded-xl border border-line bg-subtle" role="group" aria-label="Moodboard">
        <div class="w-44 rounded-lg bg-surface p-4">Brand refresh</div>
        <span class="rounded-full bg-primary px-4 py-2 text-on-primary">Kopi susu</span>
        <span data-x="90" data-y="10" data-rotate="8" class="rounded-md border border-line bg-surface px-3 py-1.5">Batik pattern</span>
    </x-markas.drag-elements>

    Needs Alpine.js.

    import { DragElements } from "@/components/markas/DragElements";
    
    <DragElements
      release="return"
      className="h-80 rounded-xl border border-line bg-subtle"
      role="group"
      aria-label="Skills"
    >
      <span className="rounded-full bg-primary-soft px-3 py-1.5">Laravel</span>
      <span className="rounded-full bg-primary-soft px-3 py-1.5">Vue</span>
    </DragElements>;
    <template>
      <DragElements
        release="stay"
        :rotate="0"
        class="h-80 rounded-xl border border-line bg-canvas"
        role="group"
        aria-label="Team"
      >
        <div data-x="8" data-y="10" class="w-48 rounded-xl bg-surface p-3">
          Rania Putri
        </div>
        <div data-x="92" data-y="30" class="w-48 rounded-xl bg-surface p-3">
          Bima Saputra
        </div>
      </DragElements>
    </template>
    <script lang="ts">
      import DragElements from "$lib/components/markas/DragElements.svelte";
    </script>
    
    <DragElements
      release="return"
      class="h-80 rounded-xl border border-line bg-subtle"
      role="group"
      aria-label="Skills"
    >
      <span class="rounded-full bg-primary-soft px-3 py-1.5">Laravel</span>
      <span class="rounded-full bg-primary-soft px-3 py-1.5">Vue</span>
    </DragElements>
    ---
    import DragElements from "@/components/markas/DragElements.astro";
    ---
    
    <DragElements
      release="return"
      class="h-80 rounded-xl border border-line bg-subtle"
      role="group"
      aria-label="Skills"
    >
      <span class="rounded-full bg-primary-soft px-3 py-1.5">Laravel</span>
      <span class="rounded-full bg-primary-soft px-3 py-1.5">Vue</span>
    </DragElements>

    Each area is a small custom element, so it keeps working after view transitions.

    import { Component } from "@angular/core";
    import { DragElements } from "./markas/drag-elements.component";
    
    @Component({
      selector: "app-skills",
      imports: [DragElements],
      template: `
        <markas-drag-elements
          release="return"
          class="h-80 rounded-xl border border-line bg-subtle"
          role="group"
          aria-label="Skills"
        >
          <span class="rounded-full bg-primary-soft px-3 py-1.5">Laravel</span>
          <span class="rounded-full bg-primary-soft px-3 py-1.5">Vue</span>
        </markas-drag-elements>
      `,
    })
    export class Skills {}

    role, aria-label, and class move from the host to the area.

    • Each direct child becomes draggable and is placed at a seeded spot inside the area. data-x and data-y (0 to 100) and data-rotate on a child pin its start.
    • release="inertia" glides on and bounces off the edges, "stay" stops where it is dropped, "return" springs back home.
    • Focus an item with Tab, move it with the arrow keys (Shift for bigger steps), and press Escape to put it back. The item you touch comes to the front.
    • Give the area a height. Items never leave it. Positions are not saved; use it for play, not for real ordering.
    • Change the screen reader hint with hintLabel.

    Props

    NameTypeDefaultDescription
    release"inertia" | "stay" | "return""inertia"What an item does when let go: glide on with friction and bounce off the edges, stop where it is, or spring back to its starting spot.
    rotatenumber6Largest random tilt in degrees for items without data-rotate. 0 keeps them straight.
    seednumber1Changes the scattered starting spots. The same seed always gives the same layout.
    hintLabelstring"Drag to move, or use the arrow keys. Escape puts it back"Description screen readers announce for each item.
    children / slotReactNode / slot-The items. Each direct child is draggable. data-x and data-y (0 to 100, percent of the area) and data-rotate (deg) on a child set its starting spot instead of the seed.

    Accessibility

    • Each item gets tabindex="0" and a description from hintLabel, so keyboard users can reach and move it.
    • Arrow keys move the focused item 10px (Shift for 50px) and Escape returns it to where it started; the item also comes to the front.
    • Buttons, links, and fields inside an item keep working: a press on them does not start a drag.
    • With reduced motion items still follow the pointer and keys, but there is no glide, spring, or easing.

    Related components

    More markasui components with the same classes in every framework.