日本語

Customizing the CSS select arrow to any shape

​​CSS​Forms,HTML

To change the arrow on the right edge of a select, set appearance: none to remove the browser's built-in look, then draw the arrow either with an SVG in background or with ::after on a wrapping element. This is useful when you want a form's select box to match your site's design, including the dropdown arrow. In browsers that support it, appearance: base-select turns the arrow into a pseudo-element, ::picker-icon, so you can change its shape and rotate it when the list opens, all in CSS.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I read the computed values and click results by running Chromium with Playwright. I did not test how the page renders in Firefox or Safari, or the selection UI on smartphones. The browser versions for each browser come from the compatibility data (@mdn/browser-compat-data 8.1.8).

Four select elements stacked vertically. The first uses the browser's default look, with a small black arrow on the right edge. The second has only appearance: none, so it is a gray box with a thin border and no arrow or extra spacing. The third has an SVG in the background and shows a light blue arrow on the right. The fourth draws the arrow with ::after and shows a pink arrow on the right
From top: default, only appearance: none, SVG in background, arrow drawn with ::after

Match the font size first

A select does not inherit the parent's font size by default. In the test environment, when I put a select on a page where body was 16px, the select's font-size was 13.3333px. Writing font: inherit made it 16px, and the font also matched the parent.

css
select {
  font: inherit;
}

Remove the browser's look with appearance: none

Writing appearance: none removes browser-specific styling such as the arrow on the right edge. The result is a box with a gray background and a thin border, as in the second image above, so add border, padding, and background to style it. As described on MDN's appearance page, changing the appearance does not change how the select behaves.

In the test environment, the width of a select with the same options shrank from the default 71px to 51px. Since there is no longer space reserved for the arrow, leave room with right padding when you draw your own arrow.

Place an SVG arrow in the background

The simplest approach is to put an arrow SVG in background. The HTML can stay as it is.

css
select {
  font: inherit;
  appearance: none;
  border: 1px solid #9aa5ab;
  border-radius: 6px;
  padding: .5em 2.5em .5em .75em;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23067a98' stroke-width='2'/%3E%3C/svg%3E")
    no-repeat right .75em center / .75em auto;
}

Inside url(), the SVG is written directly, with < replaced by %3C and # by %23. right .75em center places the arrow .75em from the right edge, vertically centered, and / .75em auto sets its size.

The right padding leaves room for the arrow. In the test environment, I used a 200px-wide select with long options and counted the text pixels in the 40px band at the right edge. With right padding of .75em, there were 38 text pixels, running into the arrow's position. At 2.5em, the count was 0.

The stroke color of the SVG does not follow the CSS color. In the test environment, even when I set the SVG's stroke to currentColor and the select's color to red, the arrow was drawn in black. The example above writes the stroke color #067a98 directly into the SVG.

To match the arrow color to the text, draw it with ::after

Wrap the select in a span or similar element, and draw the arrow in its ::after. If the stroke color is currentColor, the arrow follows the color of the wrapping element.

html
<span class="select-wrap">
  <select>
    <option>りんご</option>
    <option>みかん</option>
    <option>ぶどう</option>
  </select>
</span>
css
.select-wrap {
  position: relative;
  display: inline-block;
  color: #d85878;
}
.select-wrap select {
  color: #1f2a30;
  /* font, appearance: none, and padding are the same as in the example above. Use only #fff for background */
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: .9em;
  top: 50%;
  width: .5em;
  height: .5em;
  translate: 0 -75%;
  rotate: 45deg;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  pointer-events: none;
}

The arrow is made by drawing only the right and bottom borders of a square and rotating it 45 degrees. In the test environment, when I set .select-wrap's color to #067a98, the ::after line color became rgb(6, 122, 152).

pointer-events: none cannot be omitted. The arrow sits on top of the select, so without this, clicking the arrow does not reach the select. In the test environment, I clicked at the arrow's position and compared the results. Without pointer-events: none, the topmost element at that position was the span, and clicking did not move focus to the select. With it, the topmost element was the select, and clicking moved focus to it. As described on MDN's pointer-events page, elements with pointer-events: none are not targets for pointer events such as clicks.

With appearance: base-select, replace only the arrow

With the methods so far, the list shown when the select opens still uses the browser's look. As explained in MDN's guide to customizable select elements, the list and the default arrow itself could not be targeted with CSS until now. With appearance: base-select, you can style the list in CSS too, and apply CSS to the arrow with ::picker-icon. As the same guide explains, you write this on both select and ::picker(select), which represents the list when it is open.

css
select,
::picker(select) {
  appearance: base-select;
}

select {
  font: inherit;
  width: 200px;
  border: 1px solid #9aa5ab;
  border-radius: 6px;
  padding: .5em .75em;
  background: #fff;
}

select::picker-icon {
  content: "";
  width: .5em;
  height: .5em;
  border-right: 2px solid #067a98;
  border-bottom: 2px solid #067a98;
  rotate: 45deg;
  transition: rotate .3s;
}

select:open::picker-icon {
  rotate: 225deg;
}

::picker(select) {
  border: 1px solid #9aa5ab;
  border-radius: 6px;
  margin-top: 4px;
  padding: 4px 0;
}

option {
  padding: .4em .75em;
}
option:checked {
  background: #eefafd;
}
option:hover {
  background: #00c8e8;
  color: #fff;
}
A select with a cyan arrow is clicked to open, then the grape option is clicked to choose it. Each click changes the click counter at the top left (a Japanese label meaning "click 1st" or "click 2nd") to a pink label. After the selection, the label at the top right (a Japanese label meaning "selected value: grape") turns pink. On the first click the list opens and the arrow rotates from pointing down to pointing up. On the second click the list closes and the arrow returns to pointing down
Clicking opens the list, and choosing an option closes it. The arrow points up only while the list is open.

MDN's ::picker-icon page explains that ::picker-icon represents the arrow, which points down when the select is closed, and that content can replace its contents. In the example above, content: "" removes the default arrow, and as in the ::after example, the arrow is drawn by rotating its border lines.

In the test environment, when I clicked this select, it matched select:open, and the rotate of ::picker-icon changed from 45deg to 225deg. Because I wrote a transition, the arrow turns over 0.3 seconds. When I clicked the grape option in the list, the select's value became the text of the grape option, and the list closed. The open list appears directly below the select. The distance from the bottom edge of the select to the top edge of the first option was 9px: the 4px margin-top plus the list's border and padding.

Even without writing anything, a "✓" appears to the left of the selected option. In the test environment, with only base-select written, the content of option::checkmark contained "✓" (computed value "✓" / ""). To remove it, write option::checkmark { display: none; }. In the test environment, the space for the "✓" disappeared, and the left edge of the option text moved from 30px to 8px from the left edge of the option.

In browsers without support, fall back to the background arrow

According to the compatibility data, appearance: base-select and ::picker() are supported from Chrome 135, Edge 135, and Safari 27 (iOS 27 too). Firefox supports appearance: base-select only when a settings flag is enabled, from version 149, and does not support ::picker(). :open is supported from Chrome 133, Edge 133, Firefox 136, and Safari 26.5.

As the MDN guide above explains, browsers without support display the select in the traditional way. Wrap the new rules in @supports: normally use the background SVG arrow, and switch to the new rules only where they are supported.

css
select {
  font: inherit;
  appearance: none;
  padding: .5em 2.5em .5em .75em;
  background: #fff url("data:image/svg+xml,…(上の例と同じ)") no-repeat right .75em center / .75em auto;
}

@supports (appearance: base-select) {
  select,
  ::picker(select) {
    appearance: base-select;
  }
  select {
    background-image: none;
  }
  /* Put the ::picker-icon and ::picker(select) rules here */
}

If you forget background-image: none, the background arrow and the ::picker-icon arrow appear side by side. In the test environment with Chromium 153, the content inside @supports was applied: appearance was base-select and background-image was none. When I rewrote the @supports condition to a value that no browser supports, appearance stayed none, and the SVG arrow in the background remained.

​Posted by 86