<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HubL - Convert hex color to hsl in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788716#M34001</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/561599"&gt;@Matthias_harms&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Unfortunately, it seems that there is no built-in filter or function in HubL to convert a hex color value to HSL. However, you can use a third-party JavaScript library such as "tinycolor" to achieve this conversion in HubL. Here's an example code snippet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set hexColor = "#ff0000" %}
{% set hslColor = execute_javascript('tinycolor("' + hexColor + '").toHslString()') %}

:root {
  --primary-color: {{ hslColor }};
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example, we first set a variable "hexColor" to the hex color value you want to convert to HSL. Then we use the "execute_javascript" function to execute JavaScript code that uses the "tinycolor" library to convert the hex color to HSL. Finally, we set the resulting HSL color as a custom property using the ":root" selector.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You can replace the "hexColor" variable with "{{theme.colors.primary.color}}" to get the primary color value from the theme.&lt;/P&gt;</description>
    <pubDate>Tue, 02 May 2023 10:21:55 GMT</pubDate>
    <dc:creator>himanshurauthan</dc:creator>
    <dc:date>2023-05-02T10:21:55Z</dc:date>
    <item>
      <title>HubL - Convert hex color to hsl</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788301#M33992</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't find any documentation for this. For some color-based calculations in CSS is it essential to have the color as a HSL value. In the HubL docs, I only find&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/cms/hubl/filters#convert-rgb" target="_blank"&gt;https://developers.hubspot.com/docs/cms/hubl/filters#convert-rgb&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do this conversion to HSL in Hubl?&lt;/P&gt;&lt;LI-CODE lang="css"&gt;:root {
  --primary-color: {{theme.colors.primary.color}};
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Best&lt;BR /&gt;&lt;BR /&gt;Matthias&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 11:19:39 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788301#M33992</guid>
      <dc:creator>Matthias_harms</dc:creator>
      <dc:date>2023-05-01T11:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: HubL - Convert hex color to hsl</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788716#M34001</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/561599"&gt;@Matthias_harms&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Unfortunately, it seems that there is no built-in filter or function in HubL to convert a hex color value to HSL. However, you can use a third-party JavaScript library such as "tinycolor" to achieve this conversion in HubL. Here's an example code snippet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set hexColor = "#ff0000" %}
{% set hslColor = execute_javascript('tinycolor("' + hexColor + '").toHslString()') %}

:root {
  --primary-color: {{ hslColor }};
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example, we first set a variable "hexColor" to the hex color value you want to convert to HSL. Then we use the "execute_javascript" function to execute JavaScript code that uses the "tinycolor" library to convert the hex color to HSL. Finally, we set the resulting HSL color as a custom property using the ":root" selector.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You can replace the "hexColor" variable with "{{theme.colors.primary.color}}" to get the primary color value from the theme.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 10:21:55 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788716#M34001</guid>
      <dc:creator>himanshurauthan</dc:creator>
      <dc:date>2023-05-02T10:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: HubL - Convert hex color to hsl</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788745#M34003</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/561599"&gt;@Matthias_harms&lt;/a&gt;,&amp;nbsp;here's a macro for this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;!--
  templateType: "page"
  isAvailableForNewContent: false
--&amp;gt;
{% macro RGBToHSL(r, g, b) -%}
  {# Make r, g, and b fractions of 1 #}
  {% set r = r / 255 %}
  {% set g = g / 255 %}
  {% set b = b / 255 %}

  {# Find greatest and smallest channel values #}
  {% set cmin = [r,g,b]|sort(False, False)|first %} 
  {% set cmax = [r,g,b]|sort(True, False)|first %} 
  {% set delta = cmax - cmin %}
  {% set h = 0 %}
  {% set s = 0 %}
  {% set l = 0 %}

  {# Calculate hue #}
  {# No difference #}
  {% if delta == 0 %}
    {% set h = 0 %}
  {# Red is max #}
  {% elif cmax == r %}
    {% set h = ((g - b) / delta) % 6 %}
  {# Green is max #}
  {% elif cmax == g %}
    {% set h = (b - r) / delta + 2 %}
  {# Blue is max #}
  {% else %}
    {% set h = (r - g) / delta + 4 %}
  {% endif %}
  
  {% set h = (h * 60)|round %}
    
  {# Make negative hues positive behind 360° #}
  {% if (h &amp;lt; 0) %}
     {% set h = h + 360 %}
  {% endif %}
  
  {# Calculate lightness #}
  {% set l = (cmax + cmin) / 2 %}

  {# Calculate saturation #}
  {% if delta == 0 %}
    {% set s = 0 %}
  {% else %}
    {% set s = delta / (1 - (2 * l - 1)|abs) %}
  {% endif %}
    
  {# Multiply l and s by 100 #}
  {% set s = (s * 100)|round %}
  {% set l = (l * 100)|round %}

  {% set return = 'hsl('~h~', '~s~'%, '~l~'%)' %}
  {{return}}
{%- endmacro %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usage:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% from '[PATH TO MACRO]/RGBToHSL macro.html' import RGBToHSL %}
{{ RGBToHSL(142, 172, 87) }}
{# outputs: "hsl(81, 34%, 51%)" #}

{# for your specific use case #}
{% set primaryColor = theme.colors.primary.color|convert_rgb|split(",") %}
:root {
  --primary-color: {{ RGBToHSL(primaryColor[0], primaryColor[1], primaryColor[2]) }};
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 11:25:21 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubL-Convert-hex-color-to-hsl/m-p/788745#M34003</guid>
      <dc:creator>piersg</dc:creator>
      <dc:date>2023-05-02T11:25:21Z</dc:date>
    </item>
  </channel>
</rss>

