Subscribe On YouTube

Join other subscribers and enjoy other Divi video tutorials!

How To Use CSS Clamp For Fluid Typography In Divi

Nelson Miller Profile Orange
In this tutorial I will give you an overview of CSS clamp and show you how to use it in Divi to make responsive fluid typography.

Use CSS Clamp In Divi

CSS Clamp can be used for many things, such as element widths, padding, margin, and much more. But the most common and most practical use case is for making fluid responsive typography. Our Divi Responsive Helper plugin already provides the only option to set sitewide global text for all modules, but you can take it even further by using CSS clamp within our settings. That’s right, you can use CSS clamp right now with the current Divi responsive helper options – no special settings required! In this tutorial I will give you an overview of what CSS clamp is and how to use it in Divi to make responsive fluid typography.

▶️ Please watch the video above to get all the exciting details! 👆

What Is CSS Clamp?

This is not a course on CSS clamp, it’s a tutorial of how to use it in Divi with our plugin. You can check out tons of other general CSS related resources to learn CSS clamp in-depth, but I’ll give you just the basics of what you need to know if you are new to this. You can also check out some articles on the Elegant Themes blog like this one about making modules responsive. The limitation is that you would need to do it for every module, unlike our plugin which does it once across the entire site. They also have this article about other fluid text options, #6 being about clamp.

CSS clamp allows us to linearly scale text between a set of minimum and maximum sizes as the viewport’s width increases and decreases. The goal is to make the size of an element (or in this case, text size) more predictable. CSS clamp is able to set responsive unit sizes without any media queries. The function uses 3 parameters in a single line, which form a perfect solution for fluid typography. The clamp() function has everything, a starting point to set the minimum font size, a middle area to set the fluid font size, and an ending point to set the maximum font size.

CSS Clamp illustration in Divi by Pee Aye Creative
text-size: clamp(minimum, preferred, maximum);

    Minimum – this fixed value is the minimum threshold for the element and cannot go lower than this. Keep this value in mind as the smallest font size you want for Phone sizes.

    Preferred – this dynamic relative value is what will be outputted unless this value falls below the minimum or above the maximum.

    Maximum – this pixel value is the maximum threshold for the element and cannot go higher than this. Keep this value in mind as the largest font size you want for Desktop sizes.

    Can CSS Clamp Be Used In The Divi Builder?

    No, not with the Divi Builder settings, the input fields will not accept it. The only way you could is by writing the CSS in the Advanced tab of every module, which is quite ridiculous. The one article from the Elegant Themes blog talks about this some. But I have to ask, why make it difficult? At that point, I wouldn’t even bother.

    How To Use CSS Clamp In Divi With The Divi Responsive Helper Plugin

    Now for the good news. It’s very easy and afters the entire site instantly with our Divi Responsive Helper plugin!

    Divi Responsive Helper Plugin by Pee Aye Creative

    Simply choose the clamp parameters you want to use and write or paste them into the font size fields in our plugin settings. Go to Divi>Themes Options>Divi Responsive Helper>Typography.

    example of CSS clamp in Divi using rem units

    You can see in that screenshot that I am using rem units, and that is because it works great in our specific situation, since we have three input fields. If you use pixel values, that works too, but because our plugin settings have an input for each device, it means you need to be more creative with the units like this:

    example of CSS clamp in Divi using pixel unites

    But this is very easy to adjust. And of course you can set the font size for all the headings H1-H6 and for paragraph text, and it only takes a few seconds and it will affect all text on the entire site. Check the video to see how perfectly smooth the text scales from small to big as the viewport changes! Pretty cool?

    Subscribe For More Things Like This!

    At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

    Blog Post Optin
    Divi Logo (2)

    Shop Our Divi Products

    Plugins • Courses • Templates

    Visit The Shop

    Featured Products

    Asset 4

    New! Trail Guides

    Follow a series of blog posts carefully arranged around a specific topic or goal! Keep track of your progress by marking posts completed, just like a free course!

    View Trial Guides

    Divi Trail Committee Membership badge with map design

    Join The Trail Committee!

    Show support for our ongoing work creating community resources at Pee-Aye Creative and enjoy exclusive member perks in return.

    Learn More

    Divi Tutorials On YouTube

    Our videos have views! Join subscribers and enjoy over video tutorials!

    Visit Our Channel

    Leave A Response!

    By commenting you agree to our Blog & YouTube Comments Policy

    17 Comments

    Comments By Members

    These comments are highlighted because they were posted by fans who have a membership on this site.

    1. Laurie Williams <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Thanks so much for the Divi responsive plugin. Saved me a LOT of time and a headaches.

      Reply

    Comments By Others

    1. David

      thanks nelson for the tutorial, I need to ask you something, with this plugin if you want an h1 to have different sizes on a desktop computer screen, for example 1024/1366/1920, it would only be enough for me to use the “H1 Heading Text Size” field – Desktop” the following values: clamp(15px, 20px, 30px)?

      Reply
    2. Leslee Langlands

      Thanks for this! It was happenstance that I was looking into clamp the same day you posted this!

      My question is, do you need to set clamp for each of the three displays? I thought that if you set the max to what your desktop would be, and your min to what you phone would be, would it not fill in the rest and you would not need the other two?

      Thanks so much! Love your tutorials.

      Reply
    3. Neil

      Hi Nelson, Thanks for this tutorial. I’ve been grappling with Clamp and using it in combination with Calc for quite a while now, looking for that magic bullet solution. The problem I’ve always found is trying to determine a way to calculate the ‘preferred’ value without trial and error.
      I’d like to have it so that at the max viewport width e.g. 1920px it is the max value in Clamp. Then is scales down linearly to the tablet break point at 980px. What I’m finding though is that unless the preferred value is correct it will reach the max or min values before the upper and lower breakpoints.

      I currently use a Calc equation in the preferred value that works perfectly but it is very time consuming putting it in all the modules for the three different Divi screen sizes as you pointed out in your video.

      So I guess in summary, how do ‘you’ determine the preferred value?

      Thanks

      Reply
    4. clarky

      Do you have a toturial for copy to clipboard? same as what you are using in the tutorial on the top?

      Reply
        • bnbae

          i will be waiting for this also

    5. ron

      as I said, I have no customizations. still no succes with paragraph.

      Reply
    6. ron

      Hi Nelson. Great post I was looking for a long time. Thanks for that

      I managed the settings in the Responsive pliugin for all H1-6 font sizes and it worked very well. Also with the help of this tutorial: https://www.fluid-type-scale.com/ 😉

      However, the paragraph font-size is not fluid. How do I set these in the plugin??

      Thanks for your help and keep up the good work.

      regards, Ron

      Reply
        • Ron Linders

          I know where it is located but paragraph text sizes for not change.
          They is no overwriting with non standard sizes. I am confused..

        • Nelson Lee Miller (aka The Divi Teacher) <span class="comment-author-role-label author-label">Author</span>

          You will need to remove any other preset/customization to the font size, that’s how our settings work. the feature works, just need to make sure it has priority so if you have any adjustment in the modules, it is designed that way on purpose to override ours.

    Submit a Comment

    Your email address will not be published. Required fields are marked *

    Recent Posts

    0

    Your Cart