Web Design

Fluid Typography Different Approaches – CSS Media Queries or CSS Clamp

Web developers are constantly working to increase UX by improving web pages and making them more user-friendly. They Work on design, framework, and content to improve user experience. Among all of these, the most important factor that influences a website is its design.

 It isn’t easy to create a design that works for everyone. It is made even more challenging by the increasing use of mobile phones. Developers must now select a font size that will work on both large and small screens. However, designers have used static font sizes with larger and smaller font size variables for both screens for longer periods. But it has limitations. Hence before the usage of fluid typography, it was a real struggle to make the content readable for all users. 

Today, many developers use fluid typography for smooth work and readability. However, it is easy to use fluid typography, but as a new developer, you should gain enough knowledge before implementing fluid typography to your website. In this article, we will discuss how fluid typography works and how we can use CSS Clamp in fluid typography. Related Article, Guide to Create HTML Email With Best Practices.

What Is Fluid Typography?

Fluid typography is a modern typographic style. As we all know, typography is the design of websites that includes color, contrast, sharpness, font size, alignment, and so on. The goal of typography is to improve the readability of websites to improve their web performance.

It is sometimes difficult to use color and font size suitable for everyone. That is where fluid typography comes in because fluid typography allows you to change the font size between maximum and minimum. Now you don’t have to worry about increasing or decreasing font size for different screen sizes. Fluid typography will fix everything.

How CSS Clamp Functions With Fluid Typography

The CSS clamp function improves the use of fluid typography. It is the form of CSS making efforts to meet developers. Requirements. The clamp function makes it simple to copy and paste the Fluid font directly into your web project. So here, developers give the size, and the rest of the mathematical calculations will be done by a clamp. 

It controls the starting and ending point of the font size of the web page and simplifies the implementation of fluid typography. But wait, this is not limited to font size clamp; it even functions for other values like length, frequency, etc. 

The clamp regulates the value between the minimum and maximum. So the font size and color contrast remain between the two values. If the values exceed the maximum limit of the value, then it uses the minimum value, and similarly, if it exceeds the minimum value, the maximum value will be used. The clamp uses the preferred value to decide the required value. 

It means that the clamp prevents the value from exceeding the low endpoint and keeps it between maximum and minimum. In this way, the clamp function aids fluid typography in maintaining the font size of websites across all screen sizes.

Clamp Function With Viewport 

Clamp in typography functions with select value because it helps to determine the required value. However, the clamp works better when the select value is in viewport width units(v w) because it helps to redefine the fluid measurements easily. 

For example, when the font size is changed in the viewport, it resizes the font with new preferred values. 

CSS clamp and viewport work together to create the responsive value that scales with the viewport width. This value in fluid typography will remain within the bounds of maximum and minimum. Related Article, Best CSS Practices for Beginners.

Fluid Typography Implementation Using CSS Function

Clamp with viewport functions this way;

Clamp ( minimum, preferred, maximum) 

Here font size with clamp will be (12px, 40px, and 200px)

The minimum value is 12px, the preferred value is 40px, and the maximum is 200px. If we use a preferred value of 40px on the web page, its width will look odd because a width below 200px does not suit the web page.

That is why instead of px, we should use the rem value of 2.6rem.

Rem values are more accessible. 2 rems are equal to 32 px. 

1rem +1 rem = 2 rem or 32 pixels. 

But this calculation will be easy with CSS because CSS will do all the calculations here.

Let’s find the font size in CSS with the following values.

We have a maximum value of 24px, minimum value of 16pxl, and preferred value of 4vw. 

The value of 10vw is 10% of the viewport width. By keeping in mind this value the following table shows us the same scenario.

Viewport Width Min Max Preferred-Value Clamp return value
320px 16px 24px 12.8px 16px
500px 16px 24px 20px 20px

Where Should We Use Fluid Typography

Fluid topography is useful for development, but still, developers do not like using it. Fluid typography works better for display text. It makes the size of the display text matches the screen size. 

Moreover, using Fluid for dates and author names is not useful, because the date size is often standard. Try to set a fallback value when using fluid typography because some browsers do not support it. 

Benefits Of Using Fluid Typography

  • Easy to use.
  • It Works better for blog pages.
  • Clamps Min and Max functions automatically send media queries when required, which means no need to write media queries.
  • Perfect for all screen types. 

Drawbacks Of using Fluid Typography

  • Professional developers can use fluid typography using CSS in a better way. Before using it, it is recommended to have good knowledge of CSS clamp and fluid typography. 
  • All browsers do not support fluid typography.
  • Sometimes extra large fonts size can be a hurdle in UI on big screens.
  • Developers do not recommend it for the IT field due to less accessibility and compatibility with various browsers. 

Wrapping Up

Fluid typography is a better choice for those who want to avoid setting size scales themselves or hate sending media queries to resize their web page’s fonts, color, and contrast. It should be avoided to use  for IT websites due to its minimum, maximum bound, and preferred value system. But fluid typography is ideal if you want an easy and quick way to set up your blog page.

You have to give it value, and it will take care of the rest. However, some developers still do not prefer fluid typography.They like to send media queries themselves while resizing the font and setting values. 

Naomi McCarthy
Naomi McCarthy

Related Articles