The future of UI is "open"

A stylable UI out of the box

Foundation of creating a good UI

UI should be ...

Common UI patterns

basic ui html elements

Choosing libraries

Frustrated developer

UI can be frustrating

There are a lot of libraries out there, but it's still really hard to create our own style to UI elements.

  • Libraries Hurting performance
  • A11Y Becoming an after-thought
  • Styling In a hacky way

Things will get better

(and about time too)

Hi, I'm Brecht

Front-end developer / DevRel

@utilitybend

Me, Brecht

Allow web developers
to style and extend built-in web UI controls

!important
The mission is not to replace current web-ui

Open UI

Open UI

Is a W3C community group working towards stylable and extendable web-UI controls. More info: open-ui.org

  • Research around parts, states and behaviour
  • Research on existing design systems
  • Mapping out the common ground

Enter

The popover API

<button popovertarget="some-popup" popovertargetaction="toggle">
    Open the popup
</button>
<div id="some-popup" popover>
  <p>Hi, i'm a popover!</p>
</div>
<button popovertarget="some-popup" popovertargetaction="show">
    Open the popup
</button>
<div id="some-popup" popover="manual">
  <p>Hi, i'm a popover!</p>
  <button popovertarget="some-popup" popovertargetaction="hide">close me!</button>
</div>

popovertargetaction

"toggle" / "show" / "hide"

popover

"auto" / "manual"
Chrome Edge Safari Firefox
[popover]:popover-open {
  /* add some styles when popover is open */
}

Or with JS

// instances
HTMLElement.showPopover();
HTMLElement.hidePopover();
HTMLElement.togglePopover();

// events
HTMLElement.beforetoggle();
HTMLElement.toggle();
Open UI

Popover

  • "auto" Light dismiss by clicking outside or use esc.
  • "manual" Provide an option to dismiss yourself
  • "hint" force-hide other hints

The popover gets added to

The top-layer

Click Me Top Layer Popover Title This popover exists in the top layer, above the rest of the DOM DOM Structure
Open UI

The top-layer

Because a popover should be on top of everything, this makes perfect sense

  • Outside of the document flow
  • No worries about z-indexes
  • Popovers in top-layer have a ::backdrop pseudo element

Animation when entering top-layer

@starting-style & transition-behavior

[popover] {
    opacity: 0;
    translate: 0 -30px;
    transition-property: opacity, translate, overlay, display;
    transition-duration: 0.8s;
    transition-behavior: allow-discrete;
    &:popover-open {
      opacity: 1;
      translate: 0;
      @starting-style {
        opacity: 0;
        translate: 0 30px;
      }
    }
  }
}

Breaking it down: transition-behavior

[popover] {
    opacity: 0;
    translate: 0 -30px;
    transition-property: opacity, translate, overlay, display;
    transition-duration: 0.8s;
    transition-behavior: allow-discrete;
    &:popover-open {
      opacity: 1;
      translate: 0;
    }
  }
}

adding @starting-style

[popover] {
    opacity: 0;
    translate: 0 -30px;
    transition-property: opacity, translate, overlay, display;
    transition-duration: 0.8s;
    transition-behavior: allow-discrete;
    &:popover-open {
      opacity: 1;
      translate: 0;
      @starting-style {
        opacity: 0;
        translate: 0 30px;
      }
    }
  }
}

transition-behavior is available in:

Chrome logo Edge logo Safari logo firefox logo

@starting-style is available in:

Chrome logo Edge logo Safari logo firefox logo(!)

Tether elements to each other

CSS Anchor positioning

This won't work

Using a wrapper and using basic relative and absolute positioning. As our popover is outside the document flow (top-layer), this won't work

/* won't work */
.button-and-pop-wrapper {
  position: relative;
}
[popover] {
  position: absolute;
}

Solution with anchoring

By using anchoring, our elements don't need to rely on their DOM position

  • Set an anchor name
  • Position our elements based on that anchor name
button {
  anchor-name: --toggletip;
}

[popover] {
  position-anchor: --toggletip;
  position-area: top;
}

anchor-tool.com by Una Kravets

Anchoring

Handeling multiple toggle-tips

<button style="--btn-anchor: --toggletip-1;" popovertarget="toggletip-1">
  first toggletip
</button>
<div style="--pop-anchor: --toggletip-1;" id="toggletip-1" role="note" popover>
  ✨Peek-a-boo✨<br />I'm a little popover
</div>

<!-- another toggletip on the page -->
<button style="--btn-anchor: --toggletip-2;" popovertarget="toggletip-2">
  second toggletip
</button>
<div style="--pop-anchor: --toggletip-2;" id="toggletip-2" role="note" popover>
  sweet🤙<br />I'm the other popover
</div>
<button style="--btn-anchor: --toggletip-1;" popovertarget="toggletip-1">
  first toggletip
</button>
<div style="--pop-anchor: --toggletip-1;" id="toggletip-1" role="note" popover>
  ✨Peek-a-boo✨<br />I'm a little popover
</div>

<!-- another toggletip on the page -->
<button style="--btn-anchor: --toggletip-2;" popovertarget="toggletip-2">
  second toggletip
</button>
<div style="--pop-anchor: --toggletip-2;" id="toggletip-2" role="note" popover>
  sweet🤙<br />I'm the other popover
</div>

Multiple toggle tips

By passing custom properties from our elements to CSS

  • Setting a unique anchor name in a custom property
  • Use our CSS to read that custom property
button {
  anchor-name: var(--btn-anchor);
}

[popover] {
  position-anchor: var(--pop-anchor);
  position-area: top;
}

Keep it in the window

position-try-fallbacks

position-try-fallbacks Keywords

flip-block || flip-inline || flip-start

position-try-fallbacks

button  {
  anchor-name: var(--anchor-name);
}

[popover] {
  position-anchor: var(--pop-anchor);
  position-area: top;
  position-try-fallbacks: flip-block;
}

Work in progress
¯\_(ツ)_/¯

Flippin'

button  {
  anchor-name: var(--anchor-name);
}

[popover] {
  position-anchor: var(--pop-anchor);
  position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
}

There is much more...

Anchoring is available in:

Canary logo Edge logo Edge logo

Part of interop 2025

Open UI

The popover ⚠️

Is not a dialog.

Enter

HTML Invoker commands

<button commandfor="my-dialog" command="show-modal">Opens a dialog</button>
<dialog id="my-dialog">
  This is the dialog
  <button commandfor="my-dialog" command="close">Close</button>
</dialog>
https://open-ui.org/components/invokers.explainer/
<input id="my-counter" type="number" value="0" />
<button commandfor="my-counter" command="--add-num" value="10">+10</button>
<button commandfor="my-counter" command="--add-num" value="50">+50</button>
<button commandfor="my-counter" command="--add-num" value="100">+100</button>
https://open-ui.org/components/invokers.explainer/
const counter = document.getElementById("my-counter");
counter.addEventListener("command", (e) => {
    if (e.command === "--add-num") {
        counter.value = Number(counter.value) + Number(e.source.value);
    }
});

Invoker commands are available in:

(dialogs, popovers, custom controls)
Chrome logo Edge logo Safari TP logo
⚠️ Warning ⚠️
Experimental features ahead

Experimental features

• • •

  1. Use Chrome Canary
  2. Open it with CLI using flags:
    --enable-features=HTMLInvokeActionsV2,HTMLCommandActionsV2
<button commandfor="my-video" command="play">
    Play
</button>
<video id="my-video"><!-- sources --></video>

Experimental commands are available in:

Canary logo

More Open UI goodies

Exclusive accordions

<details name="my-accordion">
  <summary>
    This is an example
  </summary>
    <!-- content -->
</details>
<details name="my-accordion" open>
  <summary>
    Of an accordion
  </summary>
    <!-- content -->
</details>

Currently available in:

Chrome logo Edge logo Safari logo Firefox logo

Taking control of the styling

Customizable Select Element

Basic select element

The basic select

Controllable, Accessible, less stylable

  • Not possible to style the listbox
  • A lot of dependencies for some styling

A customizable select

Upgrading the HTML element

  • Backwards compatible
  • Is controllable, accessible and stylable
  • Opt-in via CSS
select,
::picker(select) {
  appearance: base-select;
}

Currently available in:

Chrome logo edge logo

Progressive enhancement

select {
  @supports (appearance: base-select) {
    &,
    &::picker(select) {
      appearance: base-select;
    }
  }
}

Real world...

select {
  appearance: none;
  @supports (appearance: base-select) {
    &,
    &::picker(select) {
      appearance: base-select;
    }
  }
}

Style for everyone

select {
  appearance: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: hotpink url("arrow.svg") right 10px center / 20px no-repeat;
  /* ... etc ... */
  @supports (appearance: base-select) {
    &,
    &::picker(select) {
      appearance: base-select;
    }
  }
}

Styling the select

select {
  /* Previous properties with background-image */
  @supports (appearance: base-select) {
    & {
      background-image: none;
    }
    &::picker-icon {
      content: "";
      background-image: url("arrow.svg");
    }
  }
}

Styling the ::picker-icon

select {
  /* Previous properties with background-image */
  @supports (appearance: base-select) {
    background-image: none;
    &::picker-icon {
      content: "";
      background-image: url("arrow.svg");
      transition: rotate 0.2s ease-out;
    }
     &:open::picker-icon {
      rotate: 180deg;
    }
  }
}

Styling the ::picker(select)

select {
  /* ... */
  @supports (appearance: base-select) {
    /* ... */
    &::picker(select) {
      padding: 0;
      margin-top: 5px;
      border: 2px solid hotpink;
    }
  }
}

Styling the options

option {
  padding: 10px;
  border-top: 1px solid plum;
  &:where(:hover, :focus, :active) {
    /* ... */
  }
  &:checked {
    /* Create my own checked style */
  }
  &::checkmark {
    display: none;
    /* Hide the little checkmark */
  }
}

Images

<select>
  <option value="pokeball">
    <img src="pokeball.svg" alt="" />
    <span class="text">Pokeball</span>
  </option>
  <option value="greatball">
    <img src="great-ball.svg" alt="" />
    <span class="text">Great ball</span>
  </option>
  <option value="ultraball">
    <img src="ultra-ball.svg" alt="" />
    <span class="text">Ultra ball</span>
  </option>
</select>

selectedcontent

<select>
  <button>
    <selectedcontent></selectedcontent>
  </button>
  <option value="pokeball">
    <img src="pokeball.svg" alt="" />
    <span class="text">Pokeball</span>
  </option>
  <!-- other options -->
</select>

visually(!) hide text

selectedcontent .text {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

Creative possibilities

Top Layer Select Option 1 Option 2 Option 3 ::picker(select)

Remember

Open UI is a work in progress

Open UI

openable, combobox, multi-select, multi-handle range sliders

And you can help

Get involved with Open UI

Go to open-ui.org

The future of UI

The future of UI

Controllable

The future of UI

Accessible

The future of UI

Stylable

The future of UI

is open