# MeasureTextSize

> Computes the size needed to display a text string based on element style values such as font, font-size, word-wrap, and so on.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.UIElements](/engine/6000.3/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule

## MeasureTextSize(string, float, MeasureMode, float, MeasureMode)

Computes the size needed to display a text string based on element style values such as font, font-size, word-wrap, and so on.

```csharp
public Vector2 MeasureTextSize(string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The text to measure.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Suggested width. Can be zero.**** (\[MeasureMode]\(/engine/6000.3/script-reference/unityengine/uielements/visualelement/measuremode)): Width restrictions.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Suggested height.**** (\[MeasureMode]\(/engine/6000.3/script-reference/unityengine/uielements/visualelement/measuremode)): Height restrictions.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [Vector2](/engine/6000.3/script-reference/unityengine/vector2.md) | The horizontal and vertical size needed to display the text string. |

## MeasureTextSize(string, float, MeasureMode, float, MeasureMode, float?)

Computes the size needed to display a text string based on element style values such as font, font-size, word-wrap, and so on.

```csharp
public Vector2 MeasureTextSize(string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode, float? fontsize = null)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The text to measure.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Suggested width. Can be zero.**** (\[MeasureMode]\(/engine/6000.3/script-reference/unityengine/uielements/visualelement/measuremode)): Width restrictions.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Suggested height.**** (\[MeasureMode]\(/engine/6000.3/script-reference/unityengine/uielements/visualelement/measuremode)): Height restrictions.**** (\[float?]\(https\://learn.microsoft.com/dotnet/api/system.nullable)): Optional parameter that override the fontSize that would be applied on the visualElement.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [Vector2](/engine/6000.3/script-reference/unityengine/vector2.md) | The horizontal and vertical size needed to display the text string. |
