Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font-size in px and in rem: Why add both to the same element?

Tags:

css

font-size

body,
button,
input,
select,
textarea {
  color: #404040;
  font-family: sans-serif;
  font-size: 16px;
  font-size: 1rem;
  line-height: 1.5; }

What does that mean and how does it work?

like image 209
9Algorithm Avatar asked Nov 17 '25 11:11

9Algorithm


2 Answers

px here is a fallback for browsers which do not support the rem unit (IE8 is a notable example).

Check out the rem Can I Use... feature for browser support.

Any browser which does not support the rem unit will instead rely on the px unit, preventing the browser from defaulting the font size to whatever it pleases.

like image 162
James Donnelly Avatar answered Nov 20 '25 02:11

James Donnelly


font-sizein pixels will be the the falback for rem when browsers won't support it.

In this case will be IE8, or IE9/10, if using font shorthand property

like image 20
dippas Avatar answered Nov 20 '25 03:11

dippas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!