# \[ANN\] miso-css: verified CSS class application via dependent types

**URL:** <https://discourse.haskell.org/t/ann-miso-css-verified-css-class-application-via-dependent-types/14187>\
**Category:** Announcements\
**Created:** [June 1, 2026, 6:36pm UTC](https://discourse.haskell.org/t/ann-miso-css-verified-css-class-application-via-dependent-types/14187 "2026-06-01T18:36:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyaitskov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dyaitskov/32/5142_2.png) [@dyaitskov](https://discourse.haskell.org/u/dyaitskov)\
**Post date:** [June 1, 2026, 6:36pm UTC](https://discourse.haskell.org/t/ann-miso-css-verified-css-class-application-via-dependent-types/14187/1 "2026-06-01T18:36:43Z")

</div>

Hi,

[miso-css](https://github.com/yaitskov/miso-css) is an evolutionary step from **css-class-bindings**.

CSS class of an atomic selector can be applied to any DOM element, but that is not true for classes used in composite selectors. Rules with partially matched selectors are silently ignored by browser and this opens door bugs during consequent changes. **css-class-binding** just cannot cope with such problem and **miso-css** uses dependent types to track what CSS classes can applied to HTML elements.

### Composing tags

Before jumping straight to style application lets get familiar with syntax for tag composition because it is different in vanilla [miso](https://hackage-content.haskell.org/package/miso).

#### Appending a child

```haskell
div_ </ p_

```

```html
<div>
  <p></p>
</div>

```

#### Adding a sibling

```haskell
ul_ </ li_ </ li_

```

```html
<ul>
  <li></li>
  <li></li>
</ul>

```

#### Appending a child to child

```haskell
body_ </ (section_ </ p_)

```

```html
<body>
  <section>
    <p></p>
  </section>
</body>

```

#### Adding CDATA

```haskell
a_ <@ "click"

```

```html
<a>click</a>

```

#### Adding a raw miso DOM chunk

```haskell
import Miso.Html qualified as MH
import Miso.Html.Property qualified as MH

go = div_ =< MH.p_ [] ["h"]

```

```html
<div>
  <p>h</p>
</div>

```

#### Adding tag attribute

```haskell
a_ =<| atr @"href" "http://link.com"

```

```html
<a href="http://link.com"></a>

```

#### Binding event handler

```haskell
button_ =! onClick YourActionDc

```

#### Applying CSS class

```haskell
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
[css|.red { color: red; }|]

div_ =. red

```

```html
<div class="red"></div>

```

#### Adding tag ID

Handmade tag id:

```haskell
div_ =# ElementId "footer"

```

Generated tag id:

```haskell
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
[css|#footer { color: red; }|]

div_ =# Footer

```

```html
<div id="footer"></div>

```

#### Mix all at once

```haskell
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
[css|.form .red { color: red; }|]

div_ =. form =# ElementId "footer"
  </ (a_ =. red =<| atr @"href" "/click.php?x=1"
      </ (span_ <@ "Click me"))

```

```html
<div class="form" id="footer>
  <a class="red" href="/click.php?x=1">
    <span>Click me</span>
  </a>
</div>

```

### Breaking rules

Until now all above samples must be valid and should type  
check. This section enumerates HTML snippets with ill-applied  
classes, expected errors and comments.

#### There can be only one

An element ID can be used once in a HTML document.

```haskell
div_ =# ElementId "Duncan MacLeod"
  </ div_ =# ElementId "Duncan MacLeod"

```

```haskell
Couldn't match type: '[DuplicatedId "Duncan MacLeod"]
               with: '[]

```

#### Parent class is missing

```haskell
[css|.a .b {}|]

div_ =. b

```

The error message is a list of triples where first element is a list of not  
applied classes, ids (hashes), tag names or attribute names.

```haskell
[([C "a"], [], [])]

```

Class **a** and **b** are missing:

```haskell
[css|.a .b .c {}|]

div_ =. c

```

```haskell
[([C "b"], [], [])
, ([C "a"], [], [])
]

```

#### B element

When selector with a child relation is partially applied the triple  
contains B element. It is a synthetic element preventing the failed  
rule from matching later somewhere upper in DOM by an accident.

```haskell
[css|.a > .b {}|]

div_ </ div_ =. b

```

```haskell
[([B, C "a"], [], [])]

```

#### One of classes is missing

Second element of triple is a list of applied classes. It helps to  
understand what worked out and what didn’t in a composite selector.

```haskell
[css|.a.b > .c {}|]

div_ =. a </ div_ =. c

```

```haskell
[([B, C "b"], [C "a"], [])]

```

##### Sibling is missing

The third element of triple explains sibling errors.

```haskell
[css|.a + .b {}|]

div_ </ div_ =. b

```

Class **a** is not applied:

```haskell
[([B], [], [[[B], [C "a"]]])]

```

### Hello World

```haskell
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}
module Miso.Css.Test.HelloWorld where

import Miso ( component, App, CSS(Style), Component(styles), View )
import Miso.Css
import Prelude

type Model = ()
type Action = ()

-- default name is "cssAsLiteralText"
renameCssTextConst "cssFromQq"

[css|
.c .b .a {
  color: #fc2c2c;
}
|]

-- instead of quasi-quoted CSS
-- the whole CSS file can be included with:
-- includeCss "assets/style.css"

app :: App Model Action
app = (component () pure viewModel)
  { styles = [Style cssFromQq] }

{-
viewModel produce following HTML snippet:

    <div class="c">
      <div class="b">
        <button class="a">
          Submit
        </button>
      </div>
    </div>

html_ and body_ don't produce tags,
because miso mount cannot be higher than body tag.

they serve just for type checking purpose
(e.g. html_ satisfies :root pseudo class)

-}
viewModel :: Model -> View Model Action
viewModel () = toView . html_ . body_ $
  div_ =. c
  </ (div_ =. b
       </ (button_ =. a
            <@ "Submit"))

```
