How to set min-font-size in CSS

nrofis picture nrofis · Jun 1, 2014 · Viewed 111.1k times · Source

I want to set a minimum font size to every element in my HTML page.

For example if there are elements with font-size less then 12px, then they will change to 12px.
But if there are elements with font-size grater then 12px, they will not change.

Is there any way to do it with CSS?

Answer

Marc Ruef picture Marc Ruef · Jun 15, 2016

In CSS3 there is a simple but brilliant hack for that:

font-size:calc(12px + 1.5vw);

This is because the static part of calc() defines the minimum. Even though the dynamic part might shrink to something near 0.