HowTo – responsive font size with CSS

Example of responsive font size where 30px is the minimum size with the smallest viewport width of 300px and where 70px is the maximum size at the largest viewport width of 1800px.

What does ‚responsive‘ mean?.
The content will adapt to the window size. It will become larger when the window becomes larger to an extent where the maximum font-size definition is reached.
Or vice versa, it will shrink the content when the window size becomes smaller.

Your CSS file will contain:

/* Example of responsive font size where 30px is the minimum size with the smallest viewport width of 300px
and where 70px is the maximum size at the largest viewport width of 1800px: */
font-size: calc(30px + (70 - 30) * ((100vw - 300px) / (1800 - 300)));

Why not simply use „vh“ or „vw“?

font-size: 10vh;

The vh will not relate to the window size in relation. It will only take either width OR height as indication and thus mess up.
To maintain the relation, use the formula as described above.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.