<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Michael Kelly</title>
    <description>The latest articles on DEV Community by Michael Kelly (@madsigntist).</description>
    <link>https://dev.to/madsigntist</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3970146%2F17245399-225e-48da-b6f6-7469c58701f9.png</url>
      <title>DEV Community: Michael Kelly</title>
      <link>https://dev.to/madsigntist</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/madsigntist"/>
    <language>en</language>
    <item>
      <title>How CSS clamp() works (and a free generator that does the math for you)</title>
      <dc:creator>Michael Kelly</dc:creator>
      <pubDate>Fri, 05 Jun 2026 16:10:15 +0000</pubDate>
      <link>https://dev.to/madsigntist/how-css-clamp-works-and-a-free-generator-that-does-the-math-for-you-2pc0</link>
      <guid>https://dev.to/madsigntist/how-css-clamp-works-and-a-free-generator-that-does-the-math-for-you-2pc0</guid>
      <description>&lt;p&gt;The CSS &lt;code&gt;clamp()&lt;/code&gt; function is one of the most useful tools in modern CSS, &lt;br&gt;
but the math to get a correct preferred value is tedious to do by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  What clamp() actually does
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;clamp(minimum, preferred, maximum)&lt;/code&gt; locks a value between a floor and ceiling &lt;br&gt;
while letting it scale proportionally between them based on viewport width.&lt;/p&gt;

&lt;p&gt;For fluid typography, the preferred value is a linear interpolation between &lt;br&gt;
two known points: the size you want at your smallest viewport, and the size &lt;br&gt;
you want at your largest.&lt;/p&gt;

&lt;h2&gt;
  
  
  The math
&lt;/h2&gt;

&lt;p&gt;Given:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;minViewport = 320px&lt;/li&gt;
&lt;li&gt;maxViewport = 1920px&lt;/li&gt;
&lt;li&gt;minSize = 1rem (16px)&lt;/li&gt;
&lt;li&gt;maxSize = 2.5rem (40px)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The formulas are:&lt;/p&gt;

&lt;p&gt;slope     = (maxSize - minSize) / (maxViewport - minViewport)&lt;br&gt;
intercept = minSize - (slope x minViewport)&lt;br&gt;
preferred = intercept + (slope x 100vw)&lt;/p&gt;

&lt;p&gt;Which produces:&lt;/p&gt;

&lt;p&gt;font-size: clamp(1rem, 0.7rem + 1.5vw, 2.5rem);&lt;/p&gt;

&lt;p&gt;That single line replaces multiple media query breakpoints and eliminates &lt;br&gt;
layout shift from abrupt size jumps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why rem instead of px
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;rem&lt;/code&gt; respects the user's browser font size preference. If someone has &lt;br&gt;
increased their base font size for accessibility, &lt;code&gt;rem&lt;/code&gt; values scale with it. &lt;br&gt;
Pixel values are absolute and override user preferences entirely. For font-size &lt;br&gt;
specifically, &lt;code&gt;rem&lt;/code&gt; is the accessible choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The generator
&lt;/h2&gt;

&lt;p&gt;I built a free tool that handles the calculation and outputs a ready-to-paste &lt;br&gt;
CSS declaration:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://clampgen.com" rel="noopener noreferrer"&gt;https://clampgen.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It supports any CSS property (not just font-size), has a rem/px toggle, &lt;br&gt;
quick presets for common type scale targets, and a breakdown panel that &lt;br&gt;
shows you the slope and intercept values so you can verify the math yourself.&lt;/p&gt;

&lt;p&gt;Built with vanilla HTML/CSS/JS and hosted on Netlify. No login, no email &lt;br&gt;
capture, just the tool.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
