I would like know why Bootstrap chose to use rem
and em
instead of px
for Bootstrap 4.
We can see an example in the variables.scss file within the project:
$font-size-h1: 2.5rem !default; $font-size-h2: 2rem !default; $font-size-h3: 1.75rem !default; $mark-padding: .2em !default;
I couldn't find any explanation by the developers on the web about this. Have they explained why they made this decision anywhere?
Using REM (or another relative length value) for font-size is a must for accessibility, because px in some browsers doesn't resize when the browser settings are changed. Some people, for example, need to zoom maybe up to 400% to be able to read your text, due to a visual impairment.
While Bootstrap uses em s or rem s for defining most sizes, px s are used for grid breakpoints and container widths. This is because the viewport width is in pixels and does not change with the font size.
By default, Bootstrap 4 uses 1rem(16px) as font size and the line-height remains 1.5. It keeps its default font-family as "Helvetica Neue," where Helvetica, sans-serif, Arial are used. Furthermore, all <p> (paragraph) elements have margin-top set to 0 and margin-bottom set to 1rem(16px).
Margin for typography ( rem ) - Case for margin between heading and paragraph. Padding for typography ( em ) - Case for different button size. Font size ( em or % ) - Case for heading font size and secondary font size. Root font size ( px ) - It is the root!
REMs are useful almost anywhere size is explicitly set.
With rem, all font sizes are relative to the root element (aka, the html tag). The reason for this is to make it easier to scale up or down for devices. You could technically change the html tag to a smaller or larger size to scale all font sizes equally – which is a super nice feature.
... [T]he main thing to take-away is everything is dynamic and relative to the root HTML tag.
For example, change the html css font-size to a different number ... and watch how the entire grid adjusts and scales.
Source: Scotch.io
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With