Is there a way to apply a CSS style on HTML5 datalist options?

107,274

Like select elements, the datalist element has very little flexibility in styling. You cannot style any of the suggested terms if that's what your question was asking.

Browsers define their own styles for these elements.

Share:
107,274

Related videos on Youtube

n0n0bstan
Author by

n0n0bstan

Updated on July 09, 2022

Comments

  • n0n0bstan
    n0n0bstan almost 2 years

    I would like to modify the way that the list of the different options of my datalist are displayed. Is it possible to apply on it some CSS properties ?

    <input list="languages" id="language_id">
    <datalist id="languages">
          <option value="html">HTML</option>
          <option value="java">Java</option>
          <option value="perl">Perl</option>
          <option value="php">PHP</option>
          <option value="ruby-on-rails">Ruby on Rails</option>
    </datalist>
    

    I tried

    option {
        background: red;
    }
    

    but it does not seem to work.

  • ANeves
    ANeves over 10 years
    Relevant: list of Firefox vendor-specific CSS extensions (which includes e.g. placeholder, but nothing like datalist): developer.mozilla.org/en-US/docs/Web/CSS/Reference/…
  • Darren Griffith
    Darren Griffith almost 10 years
    In Firefox 30, input[list] styles the textbox, but not the list. In IE 11, it styles the textbox and the list.
  • t3__rry
    t3__rry over 3 years
    I wish there was a way to consistantly alter native element's styles such as datalists and selects
  • haldo
    haldo over 3 years
    Why are you using table based layout?
  • Samz
    Samz about 3 years
    This will not working for change the background color of the datalist but can use for change the background color of the input
  • Sanan Ali
    Sanan Ali over 2 years
    The original question is how to apply styles not what are the alternatives.