# Change font size dynamically based on text length

**URL:** <https://forum.ionicframework.com/t/change-font-size-dynamically-based-on-text-length/171627>\
**Category:** Ionic Framework\
**Created:** [August 22, 2019, 1:26pm UTC](https://forum.ionicframework.com/t/change-font-size-dynamically-based-on-text-length/171627 "2019-08-22T13:26:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jefredallan](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@jefredallan](https://forum.ionicframework.com/u/jefredallan)\
**Post date:** [August 22, 2019, 1:26pm UTC](https://forum.ionicframework.com/t/change-font-size-dynamically-based-on-text-length/171627/1 "2019-08-22T13:26:02Z")

</div>

I’m a beginner at angular, ionic and coding in general. How can I change the font size of a `<p></p>` dynamically so that when the text length is less than x , the font size is bigger but when the text length is greater than x the font size is fixed.

Like this example: [http://jsfiddle.net/jfbrLjt2/](http://jsfiddle.net/jfbrLjt2/) where they used jQuery.

A little example would be greatly appreciated. Thank you.

I’m trying to implement to the code below:

```auto
<p class="posttext" *ngIf="post.message">{{ post.message }}</p>  

```

```auto
.posttext{
  display: -webkit-box;
  max-width: 100%;
  height: 85px;
  font-size: 14px;
  line-height: 1;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre-line;
  white-space: pre-wrap;

}

```

---

<div class="post-metadata">

**Author:** ![christhompson05](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/christhompson05/32/127755_2.png) [@christhompson05](https://forum.ionicframework.com/u/christhompson05)\
**Post date:** [August 22, 2019, 2:21pm UTC](https://forum.ionicframework.com/t/change-font-size-dynamically-based-on-text-length/171627/2 "2019-08-22T14:21:32Z")

</div>

You could add a second class to your element using `[ngClass]` that shrinks the font when the text is at a certain length. [https://angular.io/api/common/NgClass](https://angular.io/api/common/NgClass)
