Skip to content


shift() moves the floating element along the specified axes in order to keep it in view.

Without shift():

With shift():


import {computePosition, shift} from '@floating-ui/dom';
computePosition(referenceEl, floatingEl, {
  middleware: [shift()],


These are the options you can pass to shift().

interface Options extends DetectOverflowOptions {
  mainAxis?: boolean;
  crossAxis?: boolean;
  limiter?: {
    fn: (middlewareArguments: MiddlewareArguments) => Coords;
    options?: any;


default: true

This is the main axis in which shifting is applied.

  • x-axis for 'top' and 'bottom' placements
  • y-axis for 'left' and 'right' placements
shift({mainAxis: false});


default: false

This is the cross axis in which shifting is applied, the opposite axis of mainAxis.

Enabling this can lead to the floating element overlapping the reference element, which may not be desired and is often replaced by the flip() middleware.

shift({crossAxis: true});


default: no-op

This accepts a function that limits the shifting done, in order to prevent detachment or "overly-eager" behavior. The behavior is to stop shifting once the opposite edges of the elements are aligned.

import {shift, limitShift} from '@floating-ui/dom';
shift({limiter: limitShift()});

This function itself takes options.


default: true

Whether to apply limiting on the main axis.

  limiter: limitShift({mainAxis: false}),


default: true

Whether to apply limiting on the cross axis.

  limiter: limitShift({crossAxis: false}),


default: 0

This will offset when the limiting starts. A positive number will start limiting earlier, while negative later.

  limiter: limitShift({
    // Start limiting 5px earlier
    offset: 5,

This can also take a function, which provides the Rects of each element to read their dimensions:

  limiter: limitShift({
    // Start limiting by the reference's width earlier
    offset: ({rects, placement}) => rects.reference.width,

You may also pass an object to configure both axes:

  limiter: limitShift({
    // object
    offset: {
      mainAxis: 10,
      crossAxis: 5,
    // or a function which returns one
    offset: ({rects, placement}) => ({
      mainAxis: rects.reference.height,
      crossAxis: rects.floating.width,


All of detectOverflow's options can be passed. For instance:

shift({padding: 5}); // 0 by default

If you find the padding does not get applied on the right side, see Handling large content.


The following data is available in middlewareData.shift:

interface Data {
  x: number;
  y: number;

x and y represent how much the floating element has been shifted along that axis. The values are offsets, and therefore can be negative.