12 ms·
The <select> element can now be customized with CSS
- ruined 2y agofirefox issue https://bugzilla.mozilla.org/show_bug.cgi?id=1944403 https://bugzilla.mozilla.org/show_bug.cgi?id=1944403
- everybodyknows 2y ago> priority: Not set Last update to the issue is a pointer to test results: https://wpt.fyi/results/html/semantics/forms/the-select-element/customizable-select?label=experimental&label=master&aligned 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 2y agoDamn... been wanting this for well over two decades. About time. Still missing a good combo-box and type-ahead solution from the box.
- kelnos 2y agoWhat 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 2y 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 2y agoIgnoring 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 2y agoYou can put <span>s inside an <option>. The <option>'s `innerText` is used to populate the native control's label, meaning the inside of the spans are too. The problem is that you can't target the span in the original parser. But, you could use a template, since it's contents are ignored by text content parsers. You can have your option as: <option value="red"> <span>Normal Difficulty</span> <template>- The way it's meant to be played</template> </option> With the original parser, this will be parsed as: <option value="red">Normal Difficulty</option> And with the new parser (so long as you opt into it with the `appearance: base-select` rule): <option value="red"> <span>Normal Difficulty</span> <template>- The way it's meant to be played</template> </option> --------------------------- Then once you've opted into the new parser, you can target both the span and template to render how you want. (e.g. Give span a larger font-weight, give template a display mode of block and italicised text)
- zerocrates 2y ago
- largehotcoffee 2y agoWhy would this be preferred over creating a new HTML element, like <options>?
- minitech 2y agoBackwards compatibility. Older browsers will still be able to render the <select> and submit it as part of a form, just with its options unstyled.
- blatantly 2y 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 2y agoI 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.
- pier25 2y agoSo how long until Safari adopts this?
- ilayn 2y agoWow what's next, scrolling title text? What a time to be alive...
- darepublic 2y agotrying to write automation js for material ui dropdowns has been a PITA. This is the right direction!!
- renegade-otter 2y agoIt's been 84 years...
- codedokode 2y agoMaking web standards even more complicated one change at a time.
- peteforde 2y agoIf they keep this up, we'll soon have feature parity with VB6.
- BrenBarn 2y agoOh joy. Another way for website designers to override user display preferences.
- vntok 2y agoOn the contrary. It's CSS, you can change all of this in your browser's CSS overrides if you want.
- AbuAssar 2y agoThere should be a search box by default at the top of any <select> dropdown if there are more than n items
- paradox460 2y agoI 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 2y agoHey! 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/#searchable-dropdowns-and-grouped-lists-datalist-and-optgroup https://harrisonbroadbent.com/blog/cool-native-html-elements...
- porridgeraisin 2y agoThe rule is: Styleable XOR Unusable = 1.
- earcar 2y agoFascinating 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.
- _9hey 2y agoGreat! Now what about webtransport in WebKit?
- T3RMINATED 2y ago[dead]
- ljoshua 2y agoThe 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-select https://caniuse.com/mdn-css_properties_appearance_base-selec...
- no_wizard 2y agoThe perpetual 5 year problem of web development. I wish there was a way to do forward standards
- bsimpson 2y 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.
- paddy_m 2y agoThis 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.
- simiones 2y agoYou'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.
- ddoolin 2y agoI 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.
- deleted 2y ago[deleted]
- dpcx 2y agoThis 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 2y agoI 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.
- zachrip 2y agoThat really sucks :/
- no_wizard 2y agoHuge miss in my opinion. If it doesn’t support all scenarios I’m not sure what the Chrome team is thinking here
- kelnos 2y agoI expect they're thinking they should ship something that works, and covers some use cases, and gradually improve it over time to support more use cases. Y'know, like how most software development works.
- 8n4vidtmkvmk 2y agoThey've screwed this up several times by shipping too soon and then having to backpedal. The web is not something you want to screw up because they don't own every website in existence.
- dqv 2y agoI was just wondering how people do a custom <select multiple> now. I guess they make it screen-reader-only and then have aria-hidden checkboxes for everyone else.
- oliv__ 2y agoOh my god. This has got to be like 20 years in the making
- rbrownmh 2y agoI'd love to know the opportunity cost - billions?
- alabastervlog 2y agoThe 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.
- johnthuss 2y agoFinally! This is incredibly good news. I hope the adoption of this feature is fast - looking at you Safari.
- jillyboel 2y agoCan someone explain why this took them literal decades to do?
- codedokode 2y agoBecause HTML historically was designed for marking up text articles by hand rather than building UI with tools.
- Nesco 2y agoThere is no one truly in charge, it's a distributed standard
- LoganDark 2y agoPriorities? Profit incentives?
- NoMoreNicksLeft 2y agoAs 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).
- klabb3 2y agoBetter 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 2y 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.
- wg0 2y agoFirst 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.
- nasso_dev 2y 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 2y agoThis 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 2y ago"You" in this case is the website author. From a user perspective, that doesn't solve the problem.
- gruez 2y agoChrome 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.
- asddubs 2y agoyou're misunderstanding, this will leave the appearance of the select on mobile up to the web developer
- johannes1234321 2y 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.
- Onavo 2y agoCan we have a fully native combobox now?
- breadwinner 2y agoThis 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.
- chias 2y agoThe <select> element can now be customized with CSS *in Chromium browsers*
- indie_architect 2y agoCan't wait to use it in 2030 when my work stops supporting IE11
- olyjohn 2y agoDon't worry, they'll get extended support. Again.
- robin_reala 2y agoIt’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 2y agoSo at least 5 more years until in can actually be used.
- pier25 2y agoAt least...
- spartanatreyu 2y agoFirefox already has indicated that they approve of the new proposal: https://github.com/mozilla/standards-positions/issues/1060 https://github.com/mozilla/standards-positions/issues/1060 We're only waiting on Safari now: https://github.com/WebKit/standards-positions/issues/386 https://github.com/WebKit/standards-positions/issues/386
- zb3 2y agoDevelopers, 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 2y 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.
- codedokode 2y agoFirefox 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 2y agoYou are indeed wrong. https://support.mozilla.org/en-US/kb/privacy-preserving-attribution https://support.mozilla.org/en-US/kb/privacy-preserving-attr...
- codedokode 2y agoThat is disappointing. I went into settings to turn this off but it is already turned off and I don't remember whether I did it or my distribution ships Firefox with non-recommended settings. I hope it is the latter so that I don't get disappointed in Linux distributions also. "Privacy preserving attribution" sounds like "money preserving robbery" (or money preserving tax).
- wolframhempel 2y agoThe 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...
- blatantly 2y agoOoh I can render arbitrary pixels outside the viewpoint. Like a system dialog asking for a password.
- majora2007 2y agoIt'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 2y agoWhy 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 2y 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 2y agoI have, and failed. See https://news.ycombinator.com/item?id=40265782 https://news.ycombinator.com/item?id=40265782
- sleepybrett 2y agohey, this is about 20 years late.
- butz 2y agoSome 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 2y agoThis 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.
- montag 2y agoI 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)
- userbinator 2y agomanaged 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 2y agoUnfortunately those unusably small or invisible scrollbars are the default in many browsers. Such as Firefox on Linux, which I'm using right now.
- lblume 2y agoI 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.
- johnfn 2y agoNow how do I add an text input filter? Is that another 20 year wait? :-)
- ichik 2y agoLooks pretty broken in FF 136.0.2 (missing backgrounds/boxes, the popoup menus are visible).
- rsingel 2y agoOh the irony of the Chrome dev blog failing Google's own Core Web Vitals test https://developer.chrome.com/blog/a-customizable-select https://developer.chrome.com/blog/a-customizable-select
- dmvjs 2y agoin Chrome :wince: I honestly wish they didn't add this
- hk1337 2y agomeh. 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 2y agoI'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 2y agoOne 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 2y agoYeah they are, which is IMO a good thing but it'd be better if you could link them somehow, maybe have a temporary session or something.
- Brysonbw 2y agoBeen waiting for this - hopefully this inspires more native web features to be implemented so devs can reduce their reliance on dependencies
- cellover 2y agoLove the fact that Google auto translate of the page completely breaks the page https://imgur.com/7gfXRrm https://imgur.com/7gfXRrm
- nedt 2y agoThis 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 2y agoOh ... 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 2y agowhat's to love about this?
- clownpenis_fart 2y ago[dead]