# CSS vs BabylonJS GUI questions: line height, letter spacing, inline text styles, units, calc(), and gradients

**URL:** <https://forum.babylonjs.com/t/css-vs-babylonjs-gui-questions-line-height-letter-spacing-inline-text-styles-units-calc-and-gradients/14101>\
**Category:** Questions\
**Tags:** gui\
**Created:** [September 11, 2020, 8:18pm UTC](https://forum.babylonjs.com/t/css-vs-babylonjs-gui-questions-line-height-letter-spacing-inline-text-styles-units-calc-and-gradients/14101 "2020-09-11T20:18:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kintz\_09](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kintz_09/32/6423_2.png) [@kintz\_09](https://forum.babylonjs.com/u/kintz_09)\
**Post date:** [September 11, 2020, 8:18pm UTC](https://forum.babylonjs.com/t/css-vs-babylonjs-gui-questions-line-height-letter-spacing-inline-text-styles-units-calc-and-gradients/14101/1 "2020-09-11T20:18:13Z")

</div>

I’ve got some questions about text control in BabylonJS GUI I couldn’t find answers to in the docs or on the forum.

## 1: TextBlock: Line Height

_Is there an equivalent of CSS’s `line-height` property for a TextBlock control?_

[lineSpacing](https://doc.babylonjs.com/api/classes/babylon.gui.textblock#linespacing) looks like it could be useful, but it doesn’t look like it affects line height, just the spacing between lines.

I also came across [fontOffset](https://doc.babylonjs.com/api/classes/babylon.gui.textblock#fontoffset) which has a `height` property. But I’m not sure if its safe to mess with this property.

## 2: TextBlock: Letter Spacing

_Is there an equivalent of CSS’s `letter-spacing` for a TextBock control?_

The `letter-spacing` property in [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/letter-spacing) allows us to adjust the amount of space between characters in a text. I didn’t come across any properties or accessors to help with this.

## 3: TextBock: Inline Styles

_Is it possible to have basic inline styles in a TextBlock control?_

I need to be able to format certain words within a TextBlock as italic. From what I’ve seen, it looks like there’s no way to do in BabylonJS GUI.

## 4: Units

_How can we determine what units are accepted for the various properties in controls?_

Is there documentation on what unit values are compatible with a given property?

**Color units**

- HEX
- rgb
- rgba
- hsl
- hsla
- identifiers/keywords

I believe these are all valid for a color.

**Length units**

- percentage
- px
- em
- rem
- pt
- cm
- mm
- in
- Q
- pc
- ex
- ch
- lh
- vw
- vh
- vmin
- vmax

I know _px_ and _percentage_ are valid. I’m hoping _em_, _rem_, and _pt_ could also be valid. If any of the other [CSS units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units) are valid, that’d just be a bonus.

## 5: Calc()

Can we do calculations similar to the `calc()` CSS function?

Obviously, we can do math in javascript/typescript, but is there a way to mix units like can be done in CSS? For example, this would be valid in CSS: `calc( 20% + 100px)`.

## 6: Gradients

_Like can be done in CSS, can we use a gradient as a background color or in an image?_

* * *

Any insight into these questions would be greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 11, 2020, 8:43pm UTC](https://forum.babylonjs.com/t/css-vs-babylonjs-gui-questions-line-height-letter-spacing-inline-text-styles-units-calc-and-gradients/14101/2 "2020-09-11T20:43:56Z")

</div>

Woot, that is a list 🙂

1. Line height is build with the font size. There is no additional information used: [Babylon.js/textBlock.ts at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/gui/src/2D/controls/textBlock.ts#L304)

2.Same nothing here ☹

1. Nope

2. Colors units can be anything CSS supports but lengths are only pixel or percentage

3. Nope

4. Nope

GUI is certainly not CSS (you already have wished it :)) as we need to potentially render 60 times per sec so we have to do tradeoffs.

That being said, if you are ok to contribute some missing features I will gladly check them with you

---

<div class="post-metadata">

**Author:** ![kintz\_09](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kintz_09/32/6423_2.png) [@kintz\_09](https://forum.babylonjs.com/u/kintz_09)\
**Post date:** [September 11, 2020, 11:03pm UTC](https://forum.babylonjs.com/t/css-vs-babylonjs-gui-questions-line-height-letter-spacing-inline-text-styles-units-calc-and-gradients/14101/3 "2020-09-11T23:03:40Z")

</div>

Ha! Yeah, I’m trying to be thorough as I design the VR GUI for our app. 😄

## Line Height

I have been playing with the fontOffset.height today, and I’ve got something similar to line-height working.

```auto
textBlock.onLinesReadyObservable.addOnce(() => {
    description.fontOffset.height = 32;
  })

```

This is a decent workaround for someone who wants to control line-height.

I could probably throw together a proposal for an official lineHeight property, but I’d wanna do some additional typography research.
