# How to align text elements using the $w.html?

**URL:** <https://forum.wixstudio.com/t/how-to-align-text-elements-using-the-w-html/28290>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 5, 2020, 1:53pm UTC](https://forum.wixstudio.com/t/how-to-align-text-elements-using-the-w-html/28290 "2020-04-05T13:53:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon72313111](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anon72313111](https://forum.wixstudio.com/u/anon72313111)\
**Post date:** [April 5, 2020, 1:53pm UTC](https://forum.wixstudio.com/t/how-to-align-text-elements-using-the-w-html/28290/1 "2020-04-05T13:53:50Z")

</div>

I was trying to align the text to the center on mobile using text.html, everything is working fine except the text alignment, here’s the code that I used on mobile and a photo demonstrating the purpose.

```javascript
$item('#price').html = "<span style='text-align: center; font-family: janna, arial; font-size: 20px; font-weight: bold; color: #E84A43' >" + comboPrice + "</span>";

```

Here is the photo, am I doing it wrong? If so, what’s the right way to do it?

 ![](https://us1.discourse-cdn.com/wix/original/3X/2/4/24f470fdce047819571d9091fb13f5b1335555ba.png)

Am I doing it wrong? If so, what’s the right way to do it?

Appreciate the advice.  
Ahmad

---

<div class="post-metadata">

**Author:** ![anon72313111](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anon72313111](https://forum.wixstudio.com/u/anon72313111)\
**Post date:** [April 5, 2020, 2:01pm UTC](https://forum.wixstudio.com/t/how-to-align-text-elements-using-the-w-html/28290/2 "2020-04-05T14:01:31Z")

</div>

Hi, I’ve found a way around, but I still want to know why it didn’t work.

The solution for me was to add the tag.

```javascript
$item('#price').html = "<span style='font-family: janna, arial; font-size: 20px; font-weight: bold; color: #E84A43' >" + "<center>" + comboPrice + "</center>" + "</span>";

```

Here is the result:

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/6/e6cf9b24ed4d59c611b807cbd3a68b474df05c8b.png)

---

<div class="post-metadata">

**Author:** ![alchen00](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/alchen00/32/34230_2.png) [@alchen00](https://forum.wixstudio.com/u/alchen00)\
**Post date:** [August 18, 2023, 7:20am UTC](https://forum.wixstudio.com/t/how-to-align-text-elements-using-the-w-html/28290/3 "2023-08-18T07:20:14Z")

</div>

Adding div to define text alignment worked for me.

`<div style="text-align: right;"><span style = "color:${chgColor};font-size: ${txtSize}px;"> ${chgtext} </span></div>`

text-align property may not work for elements, but only for block-level elements like div or p . You can try to wrap your span element inside a div element and apply the text-align property to the div element instead.
