Responsive Fluid Sizing System using CSS Clamp


Related:
Bricks vs Elementor – why we switched
Web page layout – with CSS flexbox and Bricks
Website Mockup Size Guide


Overview

When building fluid mobile responsiveness into a website, values are scaled down as the device’s viewport width approaches the minimum device size, somewhere between 320px and 375px.

However not everything scales at the same rate. For example large heading sizes scale down at a greater ratio when compared with paragraph sizes which often don’t scale at all. Therefore several different scales using different ratios are needed.

The system outlined here uses a small set of ratios which can be applied to any value to achieve fluid responsive sizing.

Demo usage

For example to achieve borders which start at 30px on a laptop and end at 18px on a phone, you would choose the base-6 variable and multiply it by the larger value, like so: 

calc(var(--base-6) * 30)

We’re using the base-6 variable because 18 / 30 = 0.6.

Setting it up

We’ll start by setting up a few ratio variables: base-6, base-7, base-75, base-8, base-9

The reason we only need a few of these formulas is because there are relatively few needed. 

Looking at the ratios for the font sizes below we can see that by rounding the ratios off to 0.6, 0.7, 0.75, 0.8, and 0.9, this would be sufficient to scale sizes down to values at, or very close to the required mobile sizes.

Creating the variables

Starting with the 0.6 ratio variable which we’re calling base-6, go to the Utopia Clamp Calculator and make sure your viewport min and max widths are set correctly. We’re using 320px for min and 1292px for max in our case.

Now set your @max value to 1, and the @min value to 0.6.

Add this variable to the website :root in the main stylesheet with the name base-6 and the value copied from the output. It’s important not to have a full-stop (period) character in the name, so make sure not to use the generated names. Repeat this for each ratio needed.

Here is a complete set for the values mentioned in this tutorial with a few extra values thrown in.

:root {
  --base-6: clamp(0.0375rem, 0.0293rem + 0.0412vw, 0.0625rem);
  --base-65: clamp(0.0406rem, 0.0334rem + 0.036vw, 0.0625rem);
  --base-7: clamp(0.0438rem, 0.0376rem + 0.0309vw, 0.0625rem);
  --base-75: clamp(0.0469rem, 0.0417rem + 0.0257vw, 0.0625rem);
  --base-8: clamp(0.05rem, 0.0459rem + 0.0206vw, 0.0625rem);
  --base-85: clamp(0.0531rem, 0.05rem + 0.0154vw, 0.0625rem);
  --base-9: clamp(0.0563rem, 0.0542rem + 0.0103vw, 0.0625rem);
  --base-95: clamp(0.0594rem, 0.0583rem + 0.0051vw, 0.0625rem);
}

If you’re using a page builder with variables manager like Bricks, then you can add these one by one.

Using the variables

Divide the required min (mobile) value by the max (laptop) value to get the ratio. Select the base- variable that comes closest to this.

For example if you have a font sizeof 72px on laptops that needs to be 54px on mobile, then divide 54 by 72. The ratio is 0.75, so select base-75 as the variable.

Now modify the variable as follows:

calc(var(--base-75) * 72)

We hope you find this system useful!


Related:
Bricks vs Elementor – why we switched
Web page layout – with CSS flexbox and Bricks
Website Mockup Size Guide

Featured articles

Case Study: Guardian Validator

Introduction Guardian Validator is dedicated to supporting the decentralization of the Solana blockchain. They provide a high-performance, ethical, and safe
Read more

Case Study: Voetspore Rentals

Introduction Voetspore is a hugely popular travel-themed TV series in South Africa which has been running since the year 2000.
Read more

Case Study: Henlo Coffee website

Introduction Henlo van der Westhuizen originally approached us in February 2021 to build a website for his upcoming product, a
Read more
An example of Web Design in Cape Town

Case Study: PostModern Studios

Introduction The brief was to redesign the website for PostModern Studios, a full service post production company. The website features
Read more

Case Study: Just Share website

Introduction Just Share approached several companies to refresh their branding, and redesign and rebuild their website. Ultimately our pitch was
Read more

Case Study: SNRG (Pty) Ltd

Introduction The brief was to design a website for polymer plastics which stood out very strikingly against its competitors. Challenges
Read more
The Bricks builder logo

Bricks vs Elementor: Why we switched to Bricks Builder

Related:Web page layout - with CSS flexbox and BricksWebsite Mockup Size GuideResponsive Sizing System using CSS Clamp We recently switched
Read more

Web page layout – with CSS flexbox and Bricks

Related:Bricks vs Elementor - why we switchedWebsite Mockup Size GuideResponsive Sizing System using CSS Clamp Introduction This article aims to
Read more

Responsive Fluid Sizing System using CSS Clamp

Related:Bricks vs Elementor - why we switchedWeb page layout - with CSS flexbox and BricksWebsite Mockup Size Guide Overview When
Read more