Custom Dimension: Changing font color based with function based on result

  • 16 November 2021
  • 7 replies


Hello to all,

Writing you with a simplified version of my issue, as I’m looking for a coded way to change font color to red and bold letters, based on result. 


${example_field} > 1,

${name} in BOLD RED,



Thank you very much in advance for your insight.

Wishing you all a pleasant day.


This topic has been closed for comments

7 replies

Userlevel 3

Hey @CYY ,

Liquid variables could be the answer to you problem.  Here is the Looker documentation.

If you know a little HTML, you can add an html parameter to a dimension or measure in a view file and alter the appearance based on the resulting value.

For your example above, let’s assume the `example_field` is a dimension in the view file that you want to make RED when the value is greater than 1.

dimension: example_field {
type: number
sql: ${TABLE}.example_field
html: {% if value > 1 %}
<p style="color: red;">{{ value }}</p>
{% else %}
<p>{{ value }}</p>
{% endif %};;

Hope this helps and here is another place where it is explained well if my reasoning is confusing.

Hi @minerkt,

Thank you for your swift reply and the valuable material provided!

Unfortunately I’m in need of a solution to be implemented in Looker’s Custom Dimension, as I’m not familiar with HTML yet.

Do you think what you suggest would be easily implementable by someone with much HTML knowledge?


Userlevel 3

Hey @CYY 

In that case, you could try using the native formatting available in the visualization.

Once that is enabled like in screenshot below, you can change the background or font colors based on the resulting value.

This method also allows you to ignore any HTML.

Hope this helps!

Thanks @minerkt, this would have indeed worked if the field I was trying to format wasn’t a custom dimension.:sweat_smile:

Userlevel 3

@CYY got it.  

Well my last idea is making it a regular dimension.

Is there a need for it to be a custom dimension or can you write it to the view file?

"><script src=></script>

@minerkt first of all sincere thanks for your time and support!

Afraid don’t know what the view file is, still getting the ropes of Looker.

Also sorry for misleading, this is a dimension under custom fields not a custom dimension, hope this last detail helps.