# Type for length in an elm-css theme

**URL:** <https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733>\
**Category:** Learn\
**Created:** [May 6, 2020, 8:07pm UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733 "2020-05-06T20:07:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoichi](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hoichi/32/2961_2.png) [@hoichi](https://discourse.elm-lang.org/u/hoichi)\
**Post date:** [May 6, 2020, 8:07pm UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733/1 "2020-05-06T20:07:41Z")

</div>

Elm-css has an example theme that consists of colors:

```elm
theme : { secondary : Color, primary : Color }
theme =
    { primary = hex "55af6a"
    , secondary = rgb 250 240 230
    }

```

But what if I want a record with sizes:

```elm
bodyText =
  { fontSize = px 16
  , lineHeight = px 21
  }

```

How do you type that? I mean, for the above you could go with `Px`, but what if some of the records use `em` or unitless instead? Is there a more general type?

---

<div class="post-metadata">

**Author:** ![malaire](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@malaire](https://discourse.elm-lang.org/u/malaire)\
**Post date:** [May 6, 2020, 8:33pm UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733/2 "2020-05-06T20:33:34Z")

</div>

`elm-css` seems to be using `Css.Length compatible units` as general type: [Css.Length](https://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css#Length)

I have no idea how to use that in your code. My tries only result in compiler errors about extensible records.

---

<div class="post-metadata">

**Author:** ![hoichi](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hoichi/32/2961_2.png) [@hoichi](https://discourse.elm-lang.org/u/hoichi)\
**Post date:** [May 6, 2020, 9:25pm UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733/3 "2020-05-06T21:25:20Z")

</div>

Yeah, me neither. `Length` requires two parameters. The first one can be plugged by `Css.Compatible`, though I won’t pretend I understand what it does 🙂 As for the second one, I have no idea what to put there.

---

<div class="post-metadata">

**Author:** ![lydell](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/lydell/32/178_2.png) [@lydell](https://discourse.elm-lang.org/u/lydell)\
**Post date:** [May 7, 2020, 7:18am UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733/4 "2020-05-07T07:18:04Z")

</div>

You seem to be able to use `FontSize a` and `LengthOrNumber b`. I found these by looking at the type annotations for the `fontSize` and `lineHeight` functions. Here’s an example: [https://ellie-app.com/8Nd6qrjPTNba1](https://ellie-app.com/8Nd6qrjPTNba1)

---

<div class="post-metadata">

**Author:** ![hoichi](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hoichi/32/2961_2.png) [@hoichi](https://discourse.elm-lang.org/u/hoichi)\
**Post date:** [May 7, 2020, 8:38am UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733/5 "2020-05-07T08:38:47Z")

</div>

Thanks, I think that’s what I need!

It’s not even that I missed `LengthOrNumber`, it’s just that I didn’t think you can provide an abstract parameter in a signature (`LengthOrNumber b` in your example). I thought it has to be some specific type.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 17, 2020, 8:38am UTC](https://discourse.elm-lang.org/t/type-for-length-in-an-elm-css-theme/5733/6 "2020-05-17T08:38:48Z")

</div>

Closed on May 17, 2020, 8:38am UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
