Skip to content

dpi

Size and position types for working with logical and physical pixels.

Window and webview APIs report sizes and positions in physical pixels (actual screen pixels), while most browser APIs and the window creation options use logical pixels (physical pixels divided by the monitor scale factor). The classes in this module make the unit explicit and convert between the two.

import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const size = await appWindow.innerSize(); // PhysicalSize
const logical = size.toLogical(await appWindow.scaleFactor());

They also serialize into the shape tauri::Size / tauri::Position expect, so they can be passed straight to your own commands, see Size and Position.

This package is also accessible with window.__TAURI__.dpi when app.withGlobalTauri in tauri.conf.json is set to true.

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L259

A position represented in logical pixels. For an explanation of what logical pixels are, see description of LogicalSize.

2.0.0

new LogicalPosition(x, y): LogicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L264

Parameter Type
x number
y number

LogicalPosition

new LogicalPosition(object): LogicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L265

Parameter Type
object { Logical: { x: number; y: number; }; }
object.Logical { x: number; y: number; }
object.Logical.x number
object.Logical.y number

LogicalPosition

new LogicalPosition(object): LogicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L266

Parameter Type
object { x: number; y: number; }
object.x number
object.y number

LogicalPosition

Property Modifier Type Default value Defined in
type readonly "Logical" 'Logical' Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L260
x public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L261
y public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L262

__TAURI_TO_IPC_KEY__(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L306

object

Name Type Defined in
x number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L308
y number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L309

toJSON(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L313

object

Name Type Defined in
x number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L308
y number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L309

toPhysical(scaleFactor): PhysicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L302

Converts the logical position to a physical one.

Parameter Type
scaleFactor number

PhysicalPosition

import { LogicalPosition } from '@tauri-apps/api/dpi';
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const position = new LogicalPosition(400, 500);
const physical = position.toPhysical(factor);

2.0.0


Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L41

A size represented in logical pixels. Logical pixels are scaled according to the window’s DPI scale. Most browser APIs (i.e. MouseEvent’s clientX) will return logical pixels.

For logical-pixel-based position, see LogicalPosition.

2.0.0

new LogicalSize(width, height): LogicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L46

Parameter Type
width number
height number

LogicalSize

new LogicalSize(object): LogicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L47

Parameter Type
object { Logical: { height: number; width: number; }; }
object.Logical { height: number; width: number; }
object.Logical.height number
object.Logical.width number

LogicalSize

new LogicalSize(object): LogicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L48

Parameter Type
object { height: number; width: number; }
object.height number
object.width number

LogicalSize

Property Modifier Type Default value Defined in
height public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L44
type readonly "Logical" 'Logical' Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L42
width public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L43

__TAURI_TO_IPC_KEY__(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L88

object

Name Type Defined in
height number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L91
width number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L90

toJSON(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L95

object

Name Type Defined in
height number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L91
width number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L90

toPhysical(scaleFactor): PhysicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L84

Converts the logical size to a physical one.

Parameter Type
scaleFactor number

PhysicalSize

import { LogicalSize } from '@tauri-apps/api/dpi';
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const size = new LogicalSize(400, 500);
const physical = size.toPhysical(factor);

2.0.0


Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L326

A position represented in physical pixels.

For an explanation of what physical pixels are, see description of PhysicalSize.

2.0.0

new PhysicalPosition(x, y): PhysicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L331

Parameter Type
x number
y number

PhysicalPosition

new PhysicalPosition(object): PhysicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L332

Parameter Type
object { Physical: { x: number; y: number; }; }
object.Physical { x: number; y: number; }
object.Physical.x number
object.Physical.y number

PhysicalPosition

new PhysicalPosition(object): PhysicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L333

Parameter Type
object { x: number; y: number; }
object.x number
object.y number

PhysicalPosition

Property Modifier Type Default value Defined in
type readonly "Physical" 'Physical' Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L327
x public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L328
y public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L329

__TAURI_TO_IPC_KEY__(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L373

object

Name Type Defined in
x number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L375
y number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L376

toJSON(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L380

object

Name Type Defined in
x number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L375
y number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L376

toLogical(scaleFactor): LogicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L369

Converts the physical position to a logical one.

Parameter Type
scaleFactor number

LogicalPosition

import { PhysicalPosition } from '@tauri-apps/api/dpi';
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const position = new PhysicalPosition(400, 500);
const logical = position.toLogical(factor);

2.0.0


Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L112

A size represented in physical pixels.

Physical pixels represent actual screen pixels, and are DPI-independent. For high-DPI windows, this means that any point in the window on the screen will have a different position in logical pixels LogicalSize.

For physical-pixel-based position, see PhysicalPosition.

2.0.0

new PhysicalSize(width, height): PhysicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L117

Parameter Type
width number
height number

PhysicalSize

new PhysicalSize(object): PhysicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L118

Parameter Type
object { Physical: { height: number; width: number; }; }
object.Physical { height: number; width: number; }
object.Physical.height number
object.Physical.width number

PhysicalSize

new PhysicalSize(object): PhysicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L119

Parameter Type
object { height: number; width: number; }
object.height number
object.width number

PhysicalSize

Property Modifier Type Default value Defined in
height public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L115
type readonly "Physical" 'Physical' Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L113
width public number undefined Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L114

__TAURI_TO_IPC_KEY__(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L157

object

Name Type Defined in
height number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L160
width number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L159

toJSON(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L164

object

Name Type Defined in
height number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L160
width number Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L159

toLogical(scaleFactor): LogicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L153

Converts the physical size to a logical one.

Parameter Type
scaleFactor number

LogicalSize

import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
const factor = await appWindow.scaleFactor();
const size = await appWindow.innerSize(); // PhysicalSize
const logical = size.toLogical(factor);

2.0.0


Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L417

A position represented either in physical or in logical pixels.

This type is basically a union type of LogicalPosition and PhysicalPosition but comes in handy when using tauri::Position in Rust as an argument to a command, as this class automatically serializes into a valid format so it can be deserialized correctly into tauri::Position

So instead of

import { invoke } from '@tauri-apps/api/core';
import { LogicalPosition, PhysicalPosition } from '@tauri-apps/api/dpi';
const position: LogicalPosition | PhysicalPosition = someFunction(); // where someFunction returns either LogicalPosition or PhysicalPosition
const validPosition = position instanceof LogicalPosition
? { Logical: { x: position.x, y: position.y } }
: { Physical: { x: position.x, y: position.y } }
await invoke("do_something_with_position", { position: validPosition });

You can just use Position

import { invoke } from '@tauri-apps/api/core';
import { LogicalPosition, PhysicalPosition, Position } from '@tauri-apps/api/dpi';
const position: LogicalPosition | PhysicalPosition = someFunction(); // where someFunction returns either LogicalPosition or PhysicalPosition
const validPosition = new Position(position);
await invoke("do_something_with_position", { position: validPosition });

2.1.0

new Position(position): Position;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L420

Parameter Type
position | PhysicalPosition | LogicalPosition

Position

Property Type Defined in
position | PhysicalPosition | LogicalPosition Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L418

__TAURI_TO_IPC_KEY__(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L454

object

toJSON(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L463

object

toLogical(scaleFactor): LogicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L433

Converts the wrapped position to a logical one.

Returns the inner value untouched when it already is a LogicalPosition.

Parameter Type Description
scaleFactor number The monitor scale factor, e.g. await appWindow.scaleFactor().

LogicalPosition

2.1.0

toPhysical(scaleFactor): PhysicalPosition;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L448

Converts the wrapped position to a physical one.

Returns the inner value untouched when it already is a PhysicalPosition.

Parameter Type Description
scaleFactor number The monitor scale factor, e.g. await appWindow.scaleFactor().

PhysicalPosition

2.1.0


Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L201

A size represented either in physical or in logical pixels.

This type is basically a union type of LogicalSize and PhysicalSize but comes in handy when using tauri::Size in Rust as an argument to a command, as this class automatically serializes into a valid format so it can be deserialized correctly into tauri::Size

So instead of

import { invoke } from '@tauri-apps/api/core';
import { LogicalSize, PhysicalSize } from '@tauri-apps/api/dpi';
const size: LogicalSize | PhysicalSize = someFunction(); // where someFunction returns either LogicalSize or PhysicalSize
const validSize = size instanceof LogicalSize
? { Logical: { width: size.width, height: size.height } }
: { Physical: { width: size.width, height: size.height } }
await invoke("do_something_with_size", { size: validSize });

You can just use Size

import { invoke } from '@tauri-apps/api/core';
import { LogicalSize, PhysicalSize, Size } from '@tauri-apps/api/dpi';
const size: LogicalSize | PhysicalSize = someFunction(); // where someFunction returns either LogicalSize or PhysicalSize
const validSize = new Size(size);
await invoke("do_something_with_size", { size: validSize });

2.1.0

new Size(size): Size;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L204

Parameter Type
size | PhysicalSize | LogicalSize

Size

Property Type Defined in
size | PhysicalSize | LogicalSize Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L202

__TAURI_TO_IPC_KEY__(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L238

object

toJSON(): object;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L247

object

toLogical(scaleFactor): LogicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L217

Converts the wrapped size to a logical one.

Returns the inner value untouched when it already is a LogicalSize.

Parameter Type Description
scaleFactor number The monitor scale factor, e.g. await appWindow.scaleFactor().

LogicalSize

2.1.0

toPhysical(scaleFactor): PhysicalSize;

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/dpi.ts#L232

Converts the wrapped size to a physical one.

Returns the inner value untouched when it already is a PhysicalSize.

Parameter Type Description
scaleFactor number The monitor scale factor, e.g. await appWindow.scaleFactor().

PhysicalSize

2.1.0


© 2026 Tauri Contributors. CC-BY / MIT