---
name: "getTextWidth"
type: command
status: ok
groups: ["GUI Control", "Strings"]
arma3_since: "1.98"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/getTextWidth
revid: 376640
updated: 2025-11-01T20:58:51Z
---

# getTextWidth

*Command · GUI Control, Strings · Arma 3 v1.98*

## Description

Returns estimated width of the text based on font type and size. Similar to [ctrlTextWidth](../commands/ctrlTextWidth.md) but does not require a control and can be used to estimate text width for any control including buttons. Result does not include left and right margins (hardcoded at 0.008 each).

> [!NOTE]
> This command always uses unicode (see also [forceUnicode](../commands/forceUnicode.md)).

## Syntax

```sqf
text getTextWidth [font, size]
```

**Parameters:**

- `text`: [String](../topics/String.md) - text string to measure
- `font`: [String](../topics/String.md) - (Optional since Arma 3 v2.22, default "" (system font)) font type
- `size`: [Number](../topics/Number.md) - (Optional since Arma 3 v2.22, default -1 (system font size)) font size

**Returns:** [Number](../topics/Number.md)

## Examples

### Example 1

```sqf
_textWidth = "Hello World" getTextWidth ["PuristaMedium", 0.03];
```

### Example 2

```sqf
_textWidthInclMargins = ("Hello World" getTextWidth ["PuristaMedium", 0.03]) + 0.016;
```

### Example 3

```sqf
#define MARGINS 0.016
private _ctrl = findDisplay 46 ctrlCreate ["RscText", -1];
_ctrl ctrlSetText "TestString";
_ctrl ctrlSetFont "PuristaMedium";
_ctrl ctrlSetFontHeight 0.04;
ctrlTextWidth _ctrl == ("TestString" getTextWidth ["PuristaMedium", 0.04]) + MARGINS; // true
```

## See also

[ctrlTextWidth](../commands/ctrlTextWidth.md)

## Community notes

**R3vo** — 2020-10-28

When working with multiline controls [ctrlTextWidth](../commands/ctrlTextWidth.md) or [getTextWidth](../commands/getTextWidth.md) will not return a proper value since the text will be treated as one long line.

**Solution (Execute in Eden Editor):**

```sqf
disableSerialization;

private _display = findDisplay 313 createDisplay "RscDisplayEmpty";

private _edit = _display ctrlCreate ["RscEditMulti", -1];
_edit ctrlSetPosition [0,0,1,1];
_edit ctrlSetBackgroundColor [0,0,0,1];
_edit ctrlSetFont "EtelkaMonospacePro";
_edit ctrlSetFontHeight 0.03;
_edit ctrlCommit 0;

private _longestLineWidth = 0;
private _exampleString = "abcdefghijklmnopqrstuvxyz0134567890";
private _text = "";

for "_lines" from 1 to 400 do // loop through all lines and find the longest one
{
    _lineText = _exampleString select [round random 35];
    _longestLineWidth = _longestLineWidth max (_lineText getTextWidth ["EtelkaMonospacePro", 0.03]);
    _text = _text + _lineText + endl;
};

_edit ctrlSetPositionW (_longestLineWidth + 2 * 0.008); // width of longest line + left and right margin set in engine
_edit ctrlCommit 0;
_edit ctrlSetText _text;
```

<sub>Source: [BI Community Wiki — getTextWidth](https://community.bistudio.com/wiki/getTextWidth) (revision 376640).</sub>
