# TextField

> Make a single-line text field where the user can edit a string.

## Definition

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

## TextField(string, GUILayoutOption\[])

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(string text, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Remarks

![GUILayoutTextField (TextField)](/api/media?file=/engine/6000.3/media/images/GUILayoutTextField.png)

*Text field in the GameView.*

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUILayout.TextField(stringToEdit, 25);
    }
}
```

## TextField(string, int, GUILayoutOption\[])

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(string text, int maxLength, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum length of the string. If left out, the user can type for ever and ever.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Remarks

![GUILayoutTextField (TextField)](/api/media?file=/engine/6000.3/media/images/GUILayoutTextField.png)

*Text field in the GameView.*

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUILayout.TextField(stringToEdit, 25);
    }
}
```

## TextField(string, GUIStyle, GUILayoutOption\[])

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(string text, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): The style to use. If left out, the `textArea` style from the current [GUISkin](/engine/6000.3/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Remarks

![GUILayoutTextField (TextField)](/api/media?file=/engine/6000.3/media/images/GUILayoutTextField.png)

*Text field in the GameView.*

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUILayout.TextField(stringToEdit, 25);
    }
}
```

## TextField(string, int, GUIStyle, GUILayoutOption\[])

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(string text, int maxLength, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum length of the string. If left out, the user can type for ever and ever.**** (\[GUIStyle]\(/engine/6000.3/script-reference/unityengine/guistyle)): The style to use. If left out, the `textArea` style from the current [GUISkin](/engine/6000.3/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.3/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;Additional Resources: [GUILayout.Width](/engine/6000.3/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.3/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.3/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.3/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.3/script-reference/unityengine/guilayout/minheight.md), [GUILayout.MaxHeight](/engine/6000.3/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.3/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.3/script-reference/unityengine/guilayout/expandheight.md).

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Remarks

![GUILayoutTextField (TextField)](/api/media?file=/engine/6000.3/media/images/GUILayoutTextField.png)

*Text field in the GameView.*

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUILayout.TextField(stringToEdit, 25);
    }
}
```
