# textAlign()

This function controls the **alignment** of the text you create with the [text()](https://learnpython.strivemath.com/p5-python-web/reference/text/text) function. It basically tell the computer how to understand the `x, y` coordinates the `text` function takes as parameter,  since the text is not a point anyway.\
When you say `textAlign(RIGHT)` then call `text("Hello", x, y)` the **right edge** of the word "Hello" **becomes the** `x` value you give in the text function.\
Same thing with the vertical alignment, If you use `textAlign(RIGHT, TOP)`, the top right corner becomes the `x, y` coordinates you give in the text function.\
You need to use on the predefined constants specified below.

```
textAlign(horizAlign, [vertAlign])
```

| Input      | Description                                                                        |
| ---------- | ---------------------------------------------------------------------------------- |
| horizAlign | Specifies the horizontal alignment, takes values **`CENTER, RIGHT, LEFT`**         |
| vertAlign  | Specifies the vertical alignment, takes values **`CENTER, TOP, BOTTOM, BASELINE`** |

## Examples   &#x20;

```python
    textAlign(LEFT)
    text("ABCD", 50, 25)

    textAlign(RIGHT)
    text("ABCD", 50, 50)

    textAlign(CENTER)
    text("ABCD", 50, 75)

    stroke("red")
    strokeWeight(5)
    point(50, 25)
    point(50, 50)
    point(50, 75)
```

![](https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2FXHMdXsH2i9uZkhuAmfE5%2Fimage.png?alt=media\&token=ec08afda-59c5-4786-bf1f-f7046f5eedf3)

```python
    textAlign(CENTER, TOP)
    text("ABCD", 50, 15)

    textAlign(CENTER, CENTER)
    text("ABCD", 50, 40)

    textAlign(CENTER, BOTTOM)
    text("ABCD", 50, 65)

    textAlign(CENTER, BASELINE)
    text("ABCD", 50, 90)

    stroke("red")
    strokeWeight(5)
    point(50, 15)
    point(50, 40)
    point(50, 65)
    point(50, 90)
```

![](https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2FtLwKWP7gdxww22Wr8mDN%2Fimage.png?alt=media\&token=b557dafb-fa11-41e4-a8cd-e229b772dc67)

{% hint style="info" %}
Find these documents helpful? Let the people who made them help your child learn to code at [**Strivemath**](https://www.strivemath.com/)<mark style="color:blue;">**!**</mark>

We'd love to hear your Feedback/Comments [here](https://docs.google.com/forms/d/e/1FAIpQLSeqorBAGTya-YBRI-VFjJxtgQtCz3ucGDI96K96sNyuaGuvdw/viewform?usp=sf_link).
{% endhint %}
