Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did Bootstrap 4 choose rem and em instead px?

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?

like image 248
raduken Avatar asked May 05 '16 13:05

raduken


People also ask

Why we use rem instead of px?

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.

Does Bootstrap use em or rem?

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.

What Is rem Bootstrap 4?

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).

What is the difference between px em and rem?

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!


1 Answers

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

like image 116
isherwood Avatar answered Sep 24 '22 22:09

isherwood