Drupal 8 + Twig background-color -field select How I do with twig this:

I got list -field where I got differents color:

black|Black

grey|Grey



black = background-color: #000;

grey = background-color: #eee; 



When I select Black it will appear somewhere on the node or field.

&lt;div class="black"&gt;Example&lt;/div&gt;
One way to do this is provide a field template for that field that just prints the value and no markup:

field--your-field-name.html.twig:

{% for item in items %}
  {{ item.content }}
{% endfor %}


Then in the main template, wherever you want to output that field value, you would have:

&lt;div class="{{ content.your_field_name|trim }}"&gt;Example&lt;/div&gt;


The result should be just the field value, with no whitespace, so "black" or "grey".