# dxGetTextWidth (Client)

> Measures how wide a text is on the screen, at its widest line.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Screen drawing
- **URL**: https://wiki.mymp.gg/en/dxGetTextWidth

## Syntax

```lua
float|false dxGetTextWidth(string text [, float scale = 1, string|element font = default, bool colorCoded = false])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `text` | `string` | The text. |
| `scale` | `float` | Text scale. *(default: `1`)* |
| `font` | `string\|element` | A font's name (from a pack or given to `dxCreateFont`) or a font element from `dxCreateFont`. *(default: `default`)* |
| `colorCoded` | `bool` | Leave `#RRGGBB` colour codes out of the measure. *(default: `false`)* |

## Returns

The width in pixels, or `false` when the font does not exist.

## Example

```lua
local text = "Bem-vindo"
local width = dxGetTextWidth(text, 2, "default")

addEventHandler("onClientRender", root, function()
    local sx = getScreenSize()
    dxDrawText(text, (sx - width) / 2, 40, 0, 0, tocolor(255, 255, 255), 2)
end)
```

## See also

- [dxGetTextSize (Client)](https://wiki.mymp.gg/en/dxGetTextSize.md): Measures the width and height a text takes on the screen.
- [dxGetFontHeight (Client)](https://wiki.mymp.gg/en/dxGetFontHeight.md): Returns the height of one line of text in a font.
- [dxDrawText (Client)](https://wiki.mymp.gg/en/dxDrawText.md): Draws text on the screen for one frame, inside a box.
