At the end of this Tutorial you will be able to:
You can view finished versions of the three sample web pages you will update with fluid typography in this Tutorial by clicking the links below. The finished samples will each open in a new tab of your web browser.
You created these three sample web pages and their linked stylesheets in the previous Working with Sections Tutorial and made them responsive with the Introduction to Media Queries Tutorial
Fluid typography means that the font sizes of text – headings, paragraphs, bulleted lists, menu items – on a web page ‘scale’ (shrink or expand) smoothly according to the width of the user’s viewport (screen).
The animated gif below is taken from an article on the CSS Tricks website that features the widely-used implementation of the fluid typography approach developed by Australian web designer Mike Riethmuller.
To use fluid typography in your web pages, you need to decide on two values:
You will use both the 320px and 1600px values in the so-called fluid typography equation when setting fluid values for the font-size rule in CSS.
When using the fluid typographic equation, it is best to update the web browser resets in your stylesheet file as follows:
/* ============= WEB BROWSER RESETS ============ */ * { margin: 0; padding: 0; border: none; box-sizing: border-box } html { height: 100% } body { min-height: 100%; max-width: 1600px; margin-left: auto; margin-right: auto } img { width: 100%; height: auto; display: block }
You can see that this new browser reset block includes the maximum (1600px) viewport width.
You are now ready to use the fluid typography equation from Mike Riethmuller.
At first sight, the fluid typography equation looks complex. But it becomes easy to work with if you remember the following two points:
For example, in the case of paragraph text, you might:
Your fluid typography equation for text paragraphs would then be as shown below.
p { font-size: calc(15px + (18 - 15) * ((100vw - 320px) /(1600 - 320))); }
As for the other values in the equation:
As you can see from the four examples of fluid font sizes below, you only ever need to change the smallest and largest font size values.
Here are some examples of web pages that did not use fluid typography to scale font sizes correctly for mobile phone screens.
In the remainder of this Tutorial, you will update with fluid font-size values in the stylesheet files for the page-10.html, page-11.html and page-12.html sample web pages you created previously.
Follow these steps to add fluid font-size values to the stylesheet for the page-10.html sample web page you created in a previous Tutorial.
/* ============= WEB BROWSER RESETS ============ */ * { margin: 0; padding: 0; border: none; box-sizing: border-box } html { height: 100% } body { min-height: 100%; max-width: 1600px; margin-left: auto; margin-right: auto } img { width: 100%; height: auto; display: block }
font-size: calc(44px + (84 - 44) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(20px + (28 - 20) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(26px + (48 - 26) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(18px + (20 - 18) * ((100vw - 320px) / (1600 - 320)));
Click page-10.html to view a finished sample of this web page in a new tab of your web browser.
Follow these steps to add fluid font-size values to the stylesheet for the page-11.html sample web page you created in a previous Tutorial.
/* ============= WEB BROWSER RESETS ============ */ * { margin: 0; padding: 0; border: none; box-sizing: border-box } html { height: 100% } body { min-height: 100%; max-width: 1600px; margin-left: auto; margin-right: auto } img { width: 100%; height: auto; display: block }
font-size: calc(32px + (84 - 32) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(22px + (32 - 22) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(28px + (48 - 28) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(19px + (21 - 19) * ((100vw - 320px) / (1600 - 320)));
Click page-11.html to view a finished sample of this web page in a new tab of your web browser.
Follow these steps to add fluid font-size values to the stylesheet for the page-12.html sample web page you created in a previous Tutorial.
/* ============= WEB BROWSER RESETS ============ */ * { margin: 0; padding: 0; border: none; box-sizing: border-box } html { height: 100% } body { min-height: 100%; max-width: 1600px; margin-left: auto; margin-right: auto } img { width: 100%; height: auto; display: block }
font-size: calc(48px + (84 - 48) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(22px + (28 - 22) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(32px + (48 - 32) * ((100vw - 320px) / (1600 - 320)));
font-size: calc(17px + (21 - 17) * ((100vw - 320px) / (1600 - 320)));
Click page-12.html to view a finished sample of this web page in a new tab of your web browser.
After you have finished working with your stylesheets, you are ready to upload them to your account on GitHub.
Your linked web pages will be published at web addresses similar to the following:
https://username.github.io/websites/page-10.html
https://username.github.io/websites/page-11.html
https://username.github.io/websites/page-12.html
It may take a few minutes for your uploaded files to appear on GitHub.
Return to Contents.