The <select> element can now be customized with CSS (developer.chrome.com)

496 points by tosh 2 days ago

wolframhempel 2 days ago

The fact that I'm disproportionally excited about this probably dates me as an early 2000s web developer. But since selects can do things that you simply cannot recreate in HTML, e.g. have options drop downs that extend outside the viewport boundaries, makes this a really helpful feature.

Now, do autocompletes and tag selectors next...

asddubs 2 days ago

I doubt it'll still be able to do those things. From the article:

>Using base-select loses a number of features and behaviors:

> The <select> doesn't render outside the browser pane.

> It doesn't trigger built-in mobile operating system components.

I have mixed feelings about it. Mobile users, get ready for poorly optimized select elements. On the other hand it reduces the need for javascript for styling forms, which is good

cush 2 days ago

> The <select> doesn't render outside the browser pane. ... It doesn't trigger built-in mobile operating system components.

To me, this is intrinsically what makes a <select> a <select>. Styling is great, but without these features, this doesn't really bring anything new to the table

wruza a day ago

tadfisher 2 days ago

kmeisthax 2 days ago

For the record, there's already a bunch of custom select-a-like replacement elements out there; I'm partial to select2. The main reason for this is that selects don't come with what we used to call "combobox" features; there's no type-ahead completion, and you can't lazy-load options from a larger data source because of that.

My main gripe is the loss of rendering outside the browser pane. To be clear, we already don't have that on mobile at all; if you've ever used an iPad with Stage Manager you'll note how popovers - all of them, including native apps - are neatly conformed to the bounds of the containing window. Pop-over menus are supposed to break the window pane, but they don't, for reasons I don't quite understand but can guess rhyme with the word "security".

Eric_WVGG 2 days ago

"It doesn't trigger built-in mobile operating system components." Is that part of the spec? I can see Apple deviating from that implementation.

jraph 2 days ago

wolframhempel 2 days ago

That's fair, but I assume that is the initial implementation. Surely, over time, browser vendors will want to make the full spectrum of select functionality available consistently.

caesil 2 days ago

dbbk 2 days ago

immibis 2 days ago

Mobile users are the majority of users by far. Do web designers really make their sites hostile to most of their users? (I suspect the answer is yes)

qiqitori 2 days ago

majora2007 2 days ago

It's actually crazy that we don't have a basic typeahead component or tag selector in this day and age with HTML. Every web page I've ever built has needed these components and while there are libraries out there, they all have an annoying bug here or there.

But considering we are just now getting Select tags with styling, signals how long it might take for a typeahead which is vastly more complex.

cosmic_cheese 2 days ago

Why implement broadly useful HTML widgets when you can instead put those engineering resources to work on a new WebBeer API that fetches the number of beers in the user’s fridge or something else similarly niche?

jhardy54 2 days ago

> basic typeahead

It isn’t perfect, but have you tried <datalist>?

Totally agree about tag pickers, I was bummed to see that Bootstrap didn’t have a tag selector component either.

mlhpdx 2 days ago

asddubs 2 days ago

also drag and drop rearrange

kkarpkkarp 2 days ago

> Now, do autocompletes

This is kind of ready, see datalist element.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/da...

porridgeraisin a day ago

I know about datalist, but it's the saddest autocomplete experience you can offer. If something is not fully styleable, it's automatically garbage. If it's styleable, it may be decent.

Now, I understand why datalist is not styleable the way it is implemented right now. On Android, the suggestions come on the top bar of the native keyboard, so it doesn't make sense to be able to put arbitrary divs there. But in that case, there should be an alternative styleable autocomplete element.

Another element that is unstyleable crap is <input type=file>, <audio> too.

renerick 2 days ago

> have options drop downs that extend outside the viewport boundaries

Unless this is about something different from what you mean, unfortunately, it's not the case, as stated in the article:

> Using base-select loses a number of features and behaviors:

> The <select> doesn't render outside the browser pane.

preisschild 2 days ago

<input type="datetime-local"> with automatic ISO8601 timezone offsets would be awesome too!

sublinear 2 days ago

ISO-8601 is not the correct format for serializing local time unless it's in the past.

In my experience, a local datetime picker is going to be used almost exclusively for a future date and time. What you want instead of a timezone offset is a zone ID. That way date and tzdata can handle it properly on the backend.

progmetaldev 2 days ago

ibejoeb a day ago

blatantly 2 days ago

Ooh I can render arbitrary pixels outside the viewpoint. Like a system dialog asking for a password.

ljoshua 2 days ago

The challenge till this is widely supported (caniuse.com currently pegs it at 46% globally [1]) will be using this as a progressive enhancement that does not provide a worse or unusable experience for users with browsers not supporting it yet.

In other words, don’t include critical information or functionality in the new styling that isn’t available in the underlying plain select element! But such is always a good practice anyway.

Very nice to see this taking shape though! Should be a huge improvement over the div monster that custom select box replacements often are. :)

[1] https://caniuse.com/mdn-css_properties_appearance_base-selec...

ddoolin 2 days ago

I agree that this is a huge improvement, but it's also over a decade late IMO. This should've been accomplished well before now, especially given that the issue has been there since the beginning.

pclmulqdq 2 days ago

Because frontend is frontend, Javascript frameworks dominated the conversation even for silly things like basic web forms for the past 15 years. Basic HTML/CSS is now catching up to the fact that not everyone wants to run a Javascript monstrosity for custom styling on very basic tasks.

no_wizard 2 days ago

hombre_fatal 2 days ago

ksec 2 days ago

Over TWO decades late.

It is crazy to think what we only just have in anything non JavaScript in the past 20 years.

Cthulhu_ a day ago

It's like how border-radius was added after rounded corners via images fell out of fashion.

true_religion 2 days ago

I somehow feel Safari drags its feet on basic things platform improvements because they want to focus on iOS apps instead.

alwillis 2 days ago

arp242 2 days ago

paddy_m 2 days ago

This is true, and I try not to get eager about new browser improvements for this reason. But look at the porgress over time in browser abilities, it's astounding.

The days are long but the years are short.

no_wizard 2 days ago

The perpetual 5 year problem of web development. I wish there was a way to do forward standards

bsimpson 2 days ago

> But such is always a good practice anyway.

One more reminder to develop for people who may not perceive color and shape as you do. If you're hiding critical information in your menu styles, that information is presumably inaccessible to people who are using a screen reader.

klysm a day ago

This might be a bad take, but I think developers should also consider exactly which users are using their app. If it’s the entire internet, then absolutely you need to consider backwards compatibility. If it’s an internal app, then consider not caring and using new APIs.

simiones 2 days ago

You'll probably still keep a <div>-based control in your page, and selectively hide the <select> based one or this one, or generate different HTML for different browsers if you can do that.

nasso_dev 2 days ago

> It doesn't trigger built-in mobile operating system components.

I worry about this. The built-in mobile operating system components are reliable, accessible, and responsive. I really like it when an input element opens the Android UI because I know how it works and that it is reliable. This applies to <select>, but also date/time inputs for example.

dimal 2 days ago

This is only if you opt in to base-select, so if you don't use that, everything should continue to work the same, as far as I can tell.

Macha 2 days ago

"You" in this case is the website author. From a user perspective, that doesn't solve the problem.

gruez 2 days ago

Chrome already uses plenty of non-native components. Firefox is similar. Moreover while I can understand the concern about poorly implemented components from random web developers, Google is probably the best positioned to implement a widget that faithfully replicates the native equivalent, at least on Android.

johannes1234321 2 days ago

> Chrome already uses plenty of non-native components. Firefox is similar.

This is then won't be consistent with native OS apps, but still be consistent across websites. Better than everybody doing different div+JavaScript magic which behaves slightly different across different websites.

asddubs 2 days ago

you're misunderstanding, this will leave the appearance of the select on mobile up to the web developer

butz 2 days ago

Some controls are better left unstyled. Look what happened to scrollbars: either they are too thin to grab, have bad color contrast, so it is hard to see what part to actually grab, and, finally, some smartypants have managed even to remove scrollbars altogether from their website. Sure, default select is not the prettiest control, but it gets it job done.

dimal 2 days ago

This ship sailed in 2000. We've been hacking custom select boxes since then, so we may as well pave the cowpath. And besides, as a user, I want stylable select elements. Seeing an ugly old select box in the middle of a site where everything is styled consistently is jarring.

And it doesn't get the job done. You can't put stuff like SVGs or complex DOM elements in them, which is a valid use case. Most of the time, when people create custom select boxes, they ignore accessibility. This will fix that issue.

crazygringo 2 days ago

This is more about rich HTML for the select options. Being able to select images, rows with two columns of information, extra information in a contrasting font weight, etc. This will be extremely helpful.

SoftTalker 2 days ago

Unlikely. Things need to be simple and consistent. The web is already a disaster on both of those factors and has been for a long time.

crazygringo 2 days ago

userbinator 2 days ago

managed even to remove scrollbars altogether from their website

What's worse are the custom JS ones that only appear on hover, obscuring the contents partially where they happen to be, and then when you try to drag them and accidentally move the pointer just a tiny bit off their skinny width, they disappear and you end up accidentally activating whatever element happens to be underneath.

streptomycin 2 days ago

Unfortunately those unusably small or invisible scrollbars are the default in many browsers. Such as Firefox on Linux, which I'm using right now.

lblume 2 days ago

I think this really comes down to personal preference. I also use Firefox on Linux and always find the Windows-type scrollbar to be incredibly ugly and bulky, especially on other overflow: scroll elements.

BrenBarn 2 days ago

layer8 2 days ago

Luckily Firefox allows changing that default.

65 2 days ago

I disagree. On my website I have a sidebar and a main content area. You are able to scroll through posts on the sidebar and through the content on the main content area. The sidebar is a dark color. Being able to use a thin sidebar and make the color of the sidebar dark to match the background makes the website look a lot better than having a clunky white sidebar on a dark background.

The user can still obviously see the sidebar and knows its a sidebar, it just works better with the design.

KTibow 2 days ago

Ideally web browsers would use better defaults so you wouldn't have to do this. Firefox is good with this in my opinion: scrollbars are very subtle, don't affect content width, and adapt to the `color-scheme`.

montag 2 days ago

I may not agree with your ugly scrollbars, but I will defend your right to style them.

(If you want to annoy your users, that's your prerogative)

dpcx 2 days ago

This looks like what web developers have been waiting literally decades for. Possibly replacing (eventually) a bunch of JS libraries to make this all do what we want.

I don't have Chrome installed, but I'm curious how it handles multi-select fields, as I didn't see that in the example video.

dqv 2 days ago

I just tried it in the Codepen and it reverts to a regular old UI element when it has the multiple attribute.

Also just tried it with multiple="multiple" just in case. Same behavior.

no_wizard 2 days ago

Huge miss in my opinion. If it doesn’t support all scenarios I’m not sure what the Chrome team is thinking here

kelnos 2 days ago

dqv 2 days ago

pests 2 days ago

zachrip 2 days ago

That really sucks :/

Contax 2 days ago

> This looks like what web developers have been waiting literally decades for.

Count me in. Most times it didn't matter to me but there were some cases when I wanted or needed them to have a specific style matching other elements and, yes, I could only do it -to the best I knew- with JS.

Let's see if it becomes widely supported.

chias 2 days ago

The <select> element can now be customized with CSS *in Chromium browsers*

robin_reala a day ago

It’s the web equivalent of the Twitter account that added “in mice” to medical headlines. Nice in theory, but it’ll take years before it’s usable and in all likelihood it’s just another experiment that’ll never go anywhere.

silverwind 2 days ago

So at least 5 more years until in can actually be used.

spartanatreyu 2 days ago

Firefox already has indicated that they approve of the new proposal: https://github.com/mozilla/standards-positions/issues/1060

We're only waiting on Safari now: https://github.com/WebKit/standards-positions/issues/386

pier25 2 days ago

At least...

indie_architect 2 days ago

Can't wait to use it in 2030 when my work stops supporting IE11

olyjohn 2 days ago

Don't worry, they'll get extended support. Again.

rsingel 2 days ago

Oh the irony of the Chrome dev blog failing Google's own Core Web Vitals test

https://developer.chrome.com/blog/a-customizable-select

ruined 2 days ago

everybodyknows a day ago

> priority: Not set

Last update to the issue is a pointer to test results:

https://wpt.fyi/results/html/semantics/forms/the-select-elem...

At least Safari is failing as well, currently, so the FF team has a bit of time.

tracker1 2 days ago

Damn... been wanting this for well over two decades. About time. Still missing a good combo-box and type-ahead solution from the box.

klabb3 2 days ago

Better than broken JS libs but my main concern is the layouting yank, when there are many options and how to reach them without accidentally closing the select.

> It doesn't trigger built-in mobile operating system components.

Yeah so this is scary, but how is layouting done then?

> Shown options positioned with anchor().

Ok, also experimental, but maybe this is the best part of all? Floating UI? It’s become a reusable thing with JS, it would be amazing if it was in CSS and actually worked.

pests 2 days ago

>> It doesn't trigger built-in mobile operating system components.

>Yeah so this is scary, but how is layouting done then?

Via HTML in-website, not via opening the android wheel picker or anything like that.

Onavo 2 days ago

Can we have a fully native combobox now?

breadwinner 2 days ago

This is badly needed. Until we have combobox, the <select> is best implemented as a readonly combobox, because you need to implement combobox in any case.

codedokode 2 days ago

Making web standards even more complicated one change at a time.

earcar a day ago

Fascinating timing for this feature. I suspect the AI chatbot explosion has been a major driver behind the push for richer select elements.

Have you noticed how every AI interface needs to let you choose between models? The current select element is embarrassingly inadequate when you need to show more than just text labels. You want to display model capabilities, performance indicators, context sizes - not just "GPT-4" vs "Claude 3.7" as plain text.

johnthuss 2 days ago

Finally! This is incredibly good news. I hope the adoption of this feature is fast - looking at you Safari.

ichik 2 days ago

Looks pretty broken in FF 136.0.2 (missing backgrounds/boxes, the popoup menus are visible).

peteforde 2 days ago

If they keep this up, we'll soon have feature parity with VB6.

cellover 2 days ago

Love the fact that Google auto translate of the page completely breaks the page

https://imgur.com/7gfXRrm

nedt 2 days ago

This is also very much how the page looks for me in Firefox. If it can't fail without issues it's not an option I'd select.

nedt 2 days ago

Oh ... it's actually their own integrated translation that breaks it. Now that's funny. They aren't escaping correctly. Now if someone wants to play around with that ...

efilife 2 days ago

what's to love about this?

paradox460 a day ago

I still wish it would grow some primitive filtering/searching feature. I'm very tired of having to reach for JavaScript just to let users narrow a massive list of things

hbroadbent a day ago

Hey! Actually that is possible using the <datalist> element.

If you're interested, I wrote a bit more about it here: https://harrisonbroadbent.com/blog/cool-native-html-elements...

porridgeraisin a day ago

The rule is:

Styleable XOR Unusable = 1.

largehotcoffee 2 days ago

Why would this be preferred over creating a new HTML element, like <options>?

minitech 2 days ago

Backwards compatibility. Older browsers will still be able to render the <select> and submit it as part of a form, just with its options unstyled.

kelnos 2 days ago

What I was recently disappointed to find out is that you can't have a separate "display name" for the option items. That is, when the user clicks and the dropdown opens, I want the item labels in the dropdown to be of the form "$TITLE ($SHORT_DESCRIPTION)", but then when the dropdown is closed and something is selected, the control should just read "$TITLE". There are a few hacks to sort of make that work, but they all have downsides that make them unusable for me. (The purpose for me was to make it so the <select> element doesn't take up as much horizontal space; most of the workarounds end up missing that quality.)

There was one thing that I hoped would work, but didn't, which is applying an :after pseudo-class to <option>, so something like this:

    option:after {
      content: ' (' attr(data-descr) ')';
    }

    <select>
      <option data-descr="some description">Foo</option>
      <option data-descr="some other stuff">Bar</option>
    </select>
Unfortunately this just doesn't work (I presume because <option> can't contain DOM elements aside from unstyled text), but I wonder if it will work now.

spartanatreyu 2 days ago

`attr()` has had terrible support which is a shame because it's been around for ages and could have let us do a lot of things without having to implement stuff manually.

There's another way to try it though...

I'd try putting two separate <span>s inside each option, one for the short description and one for the long description.

I'd hide one span with css if it was inside an <option> tag.

I'd hide the other span if it was inside a <selectedoption> tag.

That would probably work.

The papercut would be that when gracefully degrading back to an ordinary select element, it might show both the short and the long selections which depending on how you write the content may or may not be an issue.

zerocrates 2 days ago

Ignoring this new feature, you can't put spans inside an option, only text. It's odd that they have this example in the post for the "old" way but they show it retaining the spans.

spartanatreyu 18 hours ago

AbuAssar 2 days ago

There should be a search box by default at the top of any <select> dropdown if there are more than n items

blatantly 2 days ago

> Changes the browsers HTML parser

Sounds like you can create loops. If the select had a style element that turns this off again would it keep changing state?

vntok a day ago

I don't see how it would create a loop? It seems like the parser change only impacts <select>'s descendant elements (to stop "cleaning" them of illegal elements), not <select> itself.

jillyboel 2 days ago

Can someone explain why this took them literal decades to do?

NoMoreNicksLeft 2 days ago

As I remember the arguments from 20 years ago, there was strong pushback against changing any form inputs, which the people who did such work said should appear as the operating system itself styled them (so users would recognize them as form inputs).

Should be able to style more than just selects, after all. Why the fuck can't I change the mask character in a password field to be something other than bullets? Hah. I had better examples too, but it looks like in the past 10 years or so, they've slowly been CSS-ized. Nice. Now if I could just style half the first line (first-line does the entirety of the line or nothing).

Nesco 2 days ago

There is no one truly in charge, it's a distributed standard

codedokode 2 days ago

Because HTML historically was designed for marking up text articles by hand rather than building UI with tools.

LoganDark 2 days ago

Priorities? Profit incentives?

Brysonbw 2 days ago

Been waiting for this - hopefully this inspires more native web features to be implemented so devs can reduce their reliance on dependencies

ilayn 2 days ago

Wow what's next, scrolling title text? What a time to be alive...

darepublic 2 days ago

trying to write automation js for material ui dropdowns has been a PITA. This is the right direction!!

pier25 2 days ago

So how long until Safari adopts this?

sleepybrett 2 days ago

hey, this is about 20 years late.

renegade-otter 2 days ago

It's been 84 years...

hk1337 2 days ago

meh. it looks really nice but I would rather do the basic styling I can do now for the 99% of the times where I don't really need it.

I have said it before, everyone (Developers that use Chrome almost exclusively) says Safari is the new IE but Chrome has been slowing becoming the thing they fought against since they defeated IE.

jeffhuys a day ago

I'm sitting here for a few years already, happily using Safari as my main driver. Recently switched to Orion to get Safari + Chrome/FF plugins. Best combination.

Easy on the battery, freaking fast, low ram usage, and plugin support (ALSO on iOS, yes, uBlock on iOS). Screw firefox, screw chrome.

Yes, I also dev on Orion. The dev tools are fine.

hk1337 a day ago

One of the main features I love about Safari is that in private browsing mode, the tabs (at least) appear to be completely isolated.

If I go to Facebook and login in one tab, then open a second tab and go Facebook, it doesn't recognize that I have logged in. There's moments where that is annoying but most of the time it's useful.

jeffhuys a day ago

oliv__ 2 days ago

Oh my god. This has got to be like 20 years in the making

rbrownmh 2 days ago

I'd love to know the opportunity cost - billions?

alabastervlog 2 days ago

The cost of browsers not having extremely-basic things that they either started to implement then abandoned in a nigh-useless state (login, frames) or never even tried to have but really, really should have once it was clear "web apps" were here to stay (datasource-backed lists and tables, table sorting without more custom JS than a sort function, drag-n-drop) is truly enormous. Who knows how many millions of person-hours.

johnfn 2 days ago

Now how do I add an text input filter? Is that another 20 year wait? :-)

sbussard a day ago

Great! Now what about webtransport in WebKit?

BrenBarn 2 days ago

Oh joy. Another way for website designers to override user display preferences.

vntok a day ago

On the contrary. It's CSS, you can change all of this in your browser's CSS overrides if you want.

dmvjs 2 days ago

in Chrome :wince: I honestly wish they didn't add this

wg0 2 days ago

First time I had the idea of building UI for apps using web technologies was in 2009 I suppose. These were the times of MFC/ATL/WinForms/GTK etc.

Since then my faith in Web technologies for building UI for most apps keeps increasing.

Through pure evolution - it's the most beautiful and open platform that's most cross platform.

zb3 2 days ago

Developers, don't fall for this!

This web API scope creep makes it __harder__ to create and maintain truly independent web browsers.. you have to implement more and more and eventually we arrive at the current state of matters - all non-chromium engines are lagging behind.

Developers will happily use this, then users will notice websites "look better" in chrome and firefox will become even less relevant. Don't.. you can already achieve this without relying on chromium-only APIs.

gjsman-1000 2 days ago

> and firefox will become even less relevant

No; Firefox can easily afford financially to add this feature. Firefox is already irrelevant; no developer will shed a tear about just blocking Firefox if they refuse to implement. Boycotting won't work either, because boycotts almost never work.

misiek08 2 days ago

> Firefox is already irrelevant

Did I miss anything?

It’s still not as clumsy and resource intensive (while destroying hardware like disks) like Chrome..

kelnos 2 days ago

codedokode 2 days ago

Firefox doesn't have ad measurement and interests sharing built in yet (or am I wrong?) so it is very relevant for me. I would rather use black-and-white selects everywhere rather than having an advertising engine built into the browser.

tredre3 2 days ago