RSS FeedTwitterMastodonBlueskyShare IconHeart IconGithub IconArrow IconClock IconGUI Challenges IconHome IconNote IconBlog IconCSS IconJS IconHTML IconShows IconGit IconSpeaking IconTools IconShuffle IconNext IconPrevious IconCalendar IconCalendar Edit Icon
Example selects are shown in light mode and dark mode
My google avatar.2 min read

Custom <select> boilerplate + transitions

css

Sharing this here because it's an important starting place for working with "customizable selects."

The Boilerplate #

The first step is to give the select and it's picker appearance: base-select, which signals that you intend to build up a select from a set of base styles.

Then enable transitions on the ::picker popover.

Lastly, hook into the :open pseudo class and provide the enter and exit stage animations.

select {
  &, &::picker(select) {
    appearance: base-select;
  }
  
  &::picker(select) {
    transition: 
      display allow-discrete 1s, 
      opacity 1s, 
      overlay 1s allow-discrete
    ;
  }
  
  &:not(:open)::picker(select) {
    opacity: 0;
  }
  
  &:open::picker(select) {
    opacity: 1;
    
    @starting-style {
      opacity: 0;
    }
  }
}

Where & How to try it #

Try it on Codepen:

  1. With Canary
  2. Enable web experiments

What can I do with this? #

Glad you asked!

Here's the Codepen for the demo video at the beginning of this post:

Mentions #

Join the conversation on

107 likes
26 reposts
  • ???? Leviano Cadeirudo ????
  • Andy Bell
  • Cu & Código
  • a blocked post
  • Andy
  • Keith J Grant
  • Tony Ward
  • Ross McKay
  • Fynn Becker
  • Nilesh Prajapati
  • Daniel Dogeanu
  • Dan Q
  • Paul Shryock
  • Jak2k
  • Fogrew :verified: ????????
  • Nick Taylor
  • Slab Bulkhead
  • Zach Leatherman :11ty:
  • Bramus
  • やまのく
  • Moritz G.
  • Alan
  • Eric Portis
  • Jeroen Zwartepoorte
  • Harald Atteneder
  • Anthony Johnston

@argyleink can't come soon enough

Sara Joy :happy_pepper:Sara Joy :happy_pepper:

@argyleink wow thats damn pretty!

wakest ⁂wakest ⁂

@argyleink I'm pretty impressed that you can do all that by customising a regular <select>. So many websites re-implement <select> in javascripts with dozens of tiny little bugs.

Hugo 雨果Hugo 雨果

@argyleink oh! Fun examples! ????

BrechtBrecht

Crawl the CSS Webring