Webflow sync, pageviews & more.
NEW

How can I use the "clamp" function with Webflow? I have already placed an HTML Embed code in the body to apply custom styling, and I have set the root with my variables. However, the "clamp" function is not working. Can someone help me with this issue in Webflow?

TL;DR
  • Define CSS variables correctly inside :root {} with proper syntax.
  • Apply styles using var(--variable-name) in matching class selectors and avoid conflicts with Webflow’s built-in styles.
  • Place custom CSS in the proper location (e.g., <style> in head or Embed component) and publish the site to test functionality.

If your clamp() function isn't working in Webflow, even after using an HTML Embed for custom styling and defining root variables, it's likely due to incorrect syntax, variable scopes, or how/where the custom CSS is applied.

1. Verify Your CSS Custom Property Setup

  • Check the placement of your root variables. They should be defined within :root {} like so:
  • Example in your HTML Embed inside the <style> tag:
    ```css
    :root {
    --fluid-font-size: clamp(1rem, 2vw, 2rem);
    }
    ```
  • Ensure proper syntax. All curly braces, colons, and semicolons must be correctly placed.

2. Check Where the CSS Is Applied

  • Webflow allows custom code via HTML Embeds or via Project Settings > Custom Code.
  • For global styles, place your <style> block in:
  • Before (Project Settings > Custom Code)
  • Or directly inside your page via an Embed component in the page body, with styles scoped via classes or :root.

3. Make Sure You’re Referencing the Variable Correctly

  • To use the value defined with clamp(), reference the custom property like this:
  • font-size: var(--fluid-font-size);
  • This should be applied to the corresponding CSS class:
  • Example:
    ```css
    .responsive-text {
    font-size: var(--fluid-font-size);
    }
    ```

4. Confirm Class and Selector Match

  • Make sure the class name in your custom CSS matches what's applied to the element in Webflow Designer.
  • Use Webflow’s class selector (in the Style panel) to double-check your element has the correct class name.

5. Avoid Conflicts With Webflow Styles

  • If Webflow has already assigned a font-size or similar property, it may override your custom style.
  • To avoid conflicts, either:
  • Assign your custom class directly.
  • Use more specific selectors in your custom CSS (.page-wrapper .responsive-text).

6. Publish and Test in Live Site

  • Custom code added via <style> tags will not render correctly in Webflow Designer preview.
  • Publish the site to see if your CSS rules and clamp() function are working correctly in the browser.

Summary

To fix the clamp() function in Webflow, ensure your custom property is defined in :root with correct syntax, referenced properly using var(), and applied via a matching, non-conflicting class. Also, publish the site to test the custom CSS, as it won’t work in the Designer preview.

Rate this answer

Other Webflow Questions