A native <select> is hard to style, and its dropdown becomes unwieldy for long option lists — think of any country picker. A different route keeps the control semantic without styling the <select> itself: build the list from radio buttons and <label> elements, then let the user pick a value by scrolling it into a fixed position, similar to a combination lock or an iOS date picker.
Markup and base layout
The control is a vertical stack of labels wrapping radio inputs inside a .scroll-container. Several custom properties drive the geometry:
--itemHeightsets the height of each item.--itemGapsets the space between items.--containerHeightis the container's height: item sizes plus gaps, sized so at most seven items show at once. An odd count keeps the selected item in the vertical center.--topBitand--footBitare color stops for a striped background gradient that paints the middle band — the current selection — in orange in the demo.
Flexbox on .scroll-container arranges the items in a column:
.scroll-container {
display: flex;
flex-direction: column;
/* rest of styles */
}
Items use flex: 0 0 var(--itemHeight) so each keeps its height, with margins before the first and after the last item so every option can reach the center by scrolling.
.scroll-item {
/* SIZING & LAYOUT */
width: 90%;
box-sizing: border-box;
padding-inline: 20px;
border-radius: inherit;
/* PAINT & FONT */
background: linear-gradient(to right, rgb(242 194 66), rgb(235 122 51));
box-shadow: 0 0 4px rgb(235 122 51);
font: 16pt/var(--itemHeight) system-ui;
color: #fff;
input { appearance: none; }
abbr { float: right; } /* The airport code */
}
Scroll snapping as the selection mechanism
CSS Scroll Snapping makes the container stop on an item rather than near one. First, enable vertical scrolling so off-screen items are reachable:
.scroll-container {
overflow-y: scroll;
/* rest of styles */
}
Then scroll-snap-type forces a scroll to end directly on a snap point:
.scroll-container {
overflow-y: scroll;
scroll-snap-type: y mandatory;
/* rest of styles */
}
scroll-snap-align on each item supplies that point; with center alignment an item's vertical center meets the container's vertical center. Because selection happens by scrolling alone, items get pointer-events: none so clicks cannot select them.
As defensive CSS, the container also sets overscroll-behavior-y: none. It is optional. When the y-axis boundary is reached, further scrolling does not chain into neighboring scroll containers.
.scroll-container {
overflow-y: scroll;
scroll-snap-type: y mandatory;
overscroll-behavior-y: none;
/* rest of styles */
}
Selection state and IntersectionObserver
The checked item is styled with its own background:
.scroll-item {
/* Same styles as before */
/* If input="radio" is :checked */
&:has(:checked) {
background: rgb(229 50 34);
}
}
With pointer events disabled, nothing in CSS can produce that :checked state, so JavaScript has to do it. An IntersectionObserver watches the .scroll-container, treating any .scroll-item crossing it as a target. The observed boundary is set with rootMargin:"-51% 0px -49% 0px", which isolates the halfway mark of the container. The callback then selects the item there via target.children[1].checked = true.
let observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
with(entry) if(isIntersecting) target.children[1].checked = true;
});
}, {
root: document.querySelector(`.scroll-container`), rootMargin: `-51% 0px -49% 0px`
});
document.querySelectorAll(`.scroll-item`).forEach(item => observer.observe(item));
Variations
Snapping to the top instead of the center
To make the selection point the top of the container, change scroll-snap-align from center to start, drop the :first-of-type top margin, and adjust the container gradient's color stops to highlight the top band instead of the middle.
Pre-selecting an item on load
Give the desired .scroll-item a .selected class. In JavaScript, read its position with getBoundingClientRect() and use scrollTo() to bring the container to that position at the selection point — the center, in the original demo.
<section class="scroll-container">
<!-- more items -->
<label class="scroll-items selected">
2024
<input type=radio name=items />
</label>
<!-- more items -->
</section>
let selected_item = (document.querySelector(".selected")).getBoundingClientRect();
let scroll_container = document.querySelector(".scroll-container");
scroll_container.scrollTo(0, selected_item.top - scroll_container.offsetHeight - selected_item.height);
A typical CodePen embed doesn't show this well; a live demo is hosted on a GitHub Page, with source code in the repository.
Before shipping
The interface must make the interaction obvious: users need to understand both how to select and which item is currently selected. In a production setting, also provide a usable fallback when JavaScript is unavailable and verify the markup's behavior with a screen reader.



