# CSS Custom Properties and Theme Fields

**URL:** <https://community.hubspot.com/t/css-custom-properties-and-theme-fields/54081>\
**Category:** CMS Development\
**Created:** [March 30, 2022, 1:03pm UTC](https://community.hubspot.com/t/css-custom-properties-and-theme-fields/54081 "2022-03-30T13:03:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SBurnett28](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@SBurnett28](https://community.hubspot.com/u/SBurnett28)\
**Post date:** [March 30, 2022, 1:03pm UTC](https://community.hubspot.com/t/css-custom-properties-and-theme-fields/54081/1 "2022-03-30T13:03:32Z")

</div>

Hi there,

I’m trying to convert the variables in the theme-overrides file to custom properties however I’m having a specific issue with the font values where, “x.font.variant” for font variants containing a font weight AND a font style (like 700 italic) are being output as “700italic” as one singular value rather than a space separated value. So when I try to use the custom variable in a CSS font property it obviously doesn’t understand 700italic as it’s supposed to be “700 italic 16px/1.5 arial” for example. I tried doing somrthing like, “x.font.font\_style.font\_weight” among other things but it doesn’t let me target the individual font styles inside the HubL styles variable.

I thought I might have to hide the variation field option (if possible) and instead add font weight/font style as individual option fields, but some of the fonts don’t have certain variations e.g. light+italic, or semi-bold, so I don’t want someone to mistakenly select that option and not see a change if that particular font doesn’t have those options.

Is there a way I’m missing so that I can target specifically the weight or style individually?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [March 31, 2022, 1:47am UTC](https://community.hubspot.com/t/css-custom-properties-and-theme-fields/54081/2 "2022-03-31T01:47:35Z")

</div>

I feel like @Gonzalo will have some thoughts on this!

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [April 7, 2022, 7:26pm UTC](https://community.hubspot.com/t/css-custom-properties-and-theme-fields/54081/3 "2022-04-07T19:26:44Z")

</div>

@SBurnett28 This is how I create a font shorthand from a theme font field.  
1. I create a seperate variable for style by checking the variant and setting my variable as “italic” if the variant contains “italic” otherwise it’s set to “normal”.  
2. Then for the weight I use |replace to just completely remove “italic” and change “regular” to 400 (you could just keep it as regular, but I like using the numbers instead lol).

```lia-code-sample
{% set style = "italic" if theme.text_font.variant is containing "italic" else "normal" %}

--{{ slug }}-font: {{
 style
 ~" "~theme.text_font.variant|replace('italic','')|replace('regular','400')
 ~" "~theme.text_font.size~"px"
 ~"/"~theme.line_height
 ~" "~font_stack(theme.text_font.font, theme.text_font.fallback) }};

```

Would be nice if Hubspot just separated those out to begin with as “style” and “weight” since that’s how it’s used in CSS…

---

<div class="post-metadata">

**Author:** ![SBurnett28](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@SBurnett28](https://community.hubspot.com/u/SBurnett28)\
**Post date:** [April 8, 2022, 8:56am UTC](https://community.hubspot.com/t/css-custom-properties-and-theme-fields/54081/4 "2022-04-08T08:56:39Z")

</div>

Hey @alyssamwilie

That’s a great trick actually, I might try that, thank you. I’m also noticing a bit of weirdness when it comes to the font fallbacks where certain fonts have a fallback baked in already (can’t remember which ones off the top of my head - I want to say Georgia or Andale Mono) and so when I use “font.font, font.fallback” the fallback is empty, meaning I have an extra comma just floating around which breaks the entire property. Have you noticed this? I managed to work around it by using an if statement but just thought it was mildly annoying (much like the font variants among other things…) to deal with. I don’t like using a ton of HubL if I don’t have to because I’m paranoid about performance!
