Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A <select> can now include rich HTML content #15617

Open
mattcroat opened this issue Mar 26, 2025 · 3 comments
Open

A <select> can now include rich HTML content #15617

mattcroat opened this issue Mar 26, 2025 · 3 comments

Comments

@mattcroat
Copy link

mattcroat commented Mar 26, 2025

Describe the bug

Before you could customize a <select>, if you put things like an image or SVG into the <option> element, the browser would ignore them, but Svelte throws an error:

Image

With the release of Chrome 135, the <select> element can now be customized using CSS and supports rich HTML content. Browsers that implement appearance: base-select will eventually support this feature.

Reproduction

This custom select example is valid in Chrome 135 and later versions.

Logs

System Info

n/a

Severity

annoyance

@mattcroat
Copy link
Author

The workaround is to put the rich HTML in a separate component or snippet:

{#snippet content()}
  <span>Svelte</span>
{/snippet}

<select>
  <option value="">🔥 Hot frameworks</option>
  <hr />
  <option value="angular">Angular</option>
  <option value="react">React</option>
  <option value="solid">Solid</option>
  <option value="svelte">
    {@render content()}
  </option>
  <option value="vue">Vue</option>
</select>

<style>
  select {
    &, &::picker(select) {
      appearance: base-select;    
    }
  }
</style>

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Mar 27, 2025

Will this only be allowed in Chrome, or is it a standardized feature? They seem to have it available as an experiment for now.

@whalderman
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants