<?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>Forem: Pablo</title>
    <description>The latest articles on Forem by Pablo (@happymvp).</description>
    <link>https://forem.com/happymvp</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%2F2459681%2Fa57e5a0d-9a5e-4b29-985b-e03d5b5c0495.jpeg</url>
      <title>Forem: Pablo</title>
      <link>https://forem.com/happymvp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/happymvp"/>
    <language>en</language>
    <item>
      <title>Web accessibility: Accessible Fluid Typography</title>
      <dc:creator>Pablo</dc:creator>
      <pubDate>Sat, 30 Nov 2024 22:52:03 +0000</pubDate>
      <link>https://forem.com/happymvp/web-accessibility-accessible-fluid-typography-49ig</link>
      <guid>https://forem.com/happymvp/web-accessibility-accessible-fluid-typography-49ig</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Before all: &lt;code&gt;font-size: 20px&lt;/code&gt; - bad practice&lt;/li&gt;
&lt;li&gt;How to make accessible fluid text&lt;/li&gt;
&lt;li&gt;Typography components in 10 minutes&lt;/li&gt;
&lt;li&gt;Inspired by&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Today I want to remind about important topic - &lt;a href="https://www.a11yproject.com/" rel="noopener noreferrer"&gt;Accessibility&lt;/a&gt;. It's a community-driven&lt;br&gt;
effort to make digital accessibility easier.&lt;/p&gt;

&lt;p&gt;Small part of this topic is typography. The text should look good with any browser font-size.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;100%&lt;/th&gt;
&lt;th&gt;200%&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhfc5pba5so82ac4lodw0.png" alt="Google search page with default browser font-size" width="800" height="500"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzp1i4d06snh80xaxmcky.png" alt="Google search page with 200% browser font-size" width="800" height="500"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Before all: &lt;code&gt;font-size: 20px&lt;/code&gt; - bad practice
&lt;/h2&gt;

&lt;p&gt;I know, we all did that, a lot of people on the internet use it in their courses. But it is a bad approach. Here is one simple rule if you are not sure which unit to choose:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;px&lt;/code&gt; - fixed-size elements that won't change, such as for borders or shadows.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rem&lt;/code&gt; - font sizes to make it accessible to users who have changed their browser's default font size.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vw / vh&lt;/code&gt; - elements sizing sticking with viewport size&lt;/p&gt;

&lt;p&gt;&lt;code&gt;%&lt;/code&gt; - elements sizing sticking with relative size&lt;/p&gt;
&lt;h2&gt;
  
  
  How to make accessible fluid text
&lt;/h2&gt;

&lt;p&gt;All we need is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/clamp" rel="noopener noreferrer"&gt;clamp()&lt;/a&gt; to make it accessible and formula to&lt;br&gt;
make it responsive.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you set global &lt;code&gt;font-size&lt;/code&gt; to &lt;code&gt;16px&lt;/code&gt;. And &lt;code&gt;line-height&lt;/code&gt; at least &lt;code&gt;1.2&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html {
  font-size: 16px; /* 1 rem */
  line-height: 1.2;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Define your minimum and maximum screen size, 320 px - 1920 px in my case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define size of your text you want to have at your minimum and maximum screen. In my example I have &lt;code&gt;h1&lt;/code&gt; tag so my&lt;br&gt;
font-size will be &lt;code&gt;50px&lt;/code&gt; and &lt;code&gt;90px&lt;/code&gt; accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to &lt;a href="https://utopia.fyi/type/calculator" rel="noopener noreferrer"&gt;https://utopia.fyi/type/calculator&lt;/a&gt; and put your values there&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjhjrm9pgwzedkya58ai.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjhjrm9pgwzedkya58ai.png" alt=" https://utopia.fyi/type/calculator screen" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scroll down to CSS Generator. We need &lt;code&gt;--step-0&lt;/code&gt; value
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Copy
   /* @link https://utopia.fyi/type/calculator?c=320,50,1.2,1920,90,1.25,2,2,&amp;amp;s=0.75|0.5|0.25,1.5|2|3|4|6,s-l&amp;amp;g=s,l,xl,12 */

:root {
--step--2: clamp(2.1701rem, 1.8842rem + 1.4299vw, 3.6rem);
--step--1: clamp(2.6042rem, 2.225rem + 1.8958vw, 4.5rem);
--step-0: clamp(3.125rem, 2.625rem + 2.5vw, 5.625rem);
--step-1: clamp(3.75rem, 3.0938rem + 3.2813vw, 7.0313rem);
--step-2: clamp(4.5rem, 3.6422rem + 4.2891vw, 8.7891rem);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Put &lt;code&gt;clamp(3.125rem, 2.625rem + 2.5vw, 5.625rem);&lt;/code&gt; as &lt;code&gt;font-size&lt;/code&gt; of your text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Result :&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;320px&lt;/th&gt;
&lt;th&gt;1920px&lt;/th&gt;
&lt;th&gt;1920px(200% zoom)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvaudnvvgpell0ion8jcc.png" alt="Screen of web page at 320 width" width="800" height="875"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiieiay0telcgzcsw9fm7.png" alt="Screen of web page at 1920 width" width="800" height="322"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08ynu8k06f5cqvlbkl3m.png" alt="Screen of web page at 1920 width with 200% zoom" width="800" height="477"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can see that with 1 line of css my text is responsive and accessible for browser scaling as well.&lt;/p&gt;
&lt;h2&gt;
  
  
  Typography components in 10 minutes
&lt;/h2&gt;

&lt;p&gt;My intention was to create flexible Typography component as fast and as flexible as possible.&lt;/p&gt;

&lt;p&gt;I took my largest &lt;code&gt;h1&lt;/code&gt; text. Went to &lt;a href="https://utopia.fyi/type/calculator" rel="noopener noreferrer"&gt;https://utopia.fyi/type/calculator&lt;/a&gt; and generated 8 downscale steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo74r217anz416ijdnrmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo74r217anz416ijdnrmh.png" alt="https://utopia.fyi/type/calculator screen" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This would be my &lt;code&gt;p, h1-6, span&lt;/code&gt; and &lt;code&gt;label&lt;/code&gt; text sizes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    --size-text-s: clamp(0.7268rem, 0.6834rem + 0.2169vw, 0.9437rem);
    --size-text-m: clamp(0.8721rem, 0.8106rem + 0.3075vw, 1.1796rem);
    --size-text-l: clamp(1.0466rem, 0.961rem + 0.428vw, 1.4746rem);
    --size-h6: clamp(1.2559rem, 1.1384rem + 0.5873vw, 1.8432rem);
    --size-h5: clamp(1.507rem, 1.3476rem + 0.797vw, 2.304rem);
    --size-h4: clamp(1.8084rem, 1.5941rem + 1.0716vw, 2.88rem);
    --size-h3: clamp(2.1701rem, 1.8842rem + 1.4299vw, 3.6rem);
    --size-h2: clamp(2.6042rem, 2.225rem + 1.8958vw, 4.5rem);
    --size-h1: clamp(3.125rem, 2.625rem + 2.5vw, 5.625rem);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then a 5 more minutes playing with react and Voilà:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/happymvp/react_ts_vite-template/tree/6db0d154909364eba01a9fd41f4ce98eb98afda2/src/components/Typography" rel="noopener noreferrer"&gt;My reusable typography components for React&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspired by
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/marcelluscaio/using-rem-doesnt-make-your-website-responsive-heres-why-4b0e"&gt;Using REM Doesn't Make Your Website Responsive - Here's Why&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/marcelluscaio/fluid-typography-1mfl"&gt;Fluid Typography&lt;/a&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>css</category>
      <category>react</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
