Problem/Motivation

In #3117698: Allow PostCSS Plugin “Px to Rem” in core for Olivero theme there was a good discussion about how and where to use REM units. See #3117698-24: Allow PostCSS Plugin “Px to Rem” in core for Olivero theme.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

alexpott created an issue. See original summary.

gauravvvv’s picture

Use rem units for sizing that doesn't need em units, and that should scale depending on browser font size settings. Use rem units unless you're sure you need em units, including on font sizes. Use rem units on media queries. Don't use em or rem in multi-column layout widths - use % instead.

Found an article for this: https://webdesign.tutsplus.com/tutorials/comprehensive-guide-when-to-use...

Madhu kumar’s picture

Thanks @Gauravmahlawat
Article help me to understand the basics about to use REM units

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

radheymkumar’s picture

@Gauravmahlawat
Thanks

Saurabh Srivastava’s picture

.

Saurabh Srivastava’s picture

Status: Active » Needs review

em units for the font-size property will be relative to the font size of the parent element.
em units on other properties than font size will be relative to the font size of the current element.
rem units sizes will always be relative to the font size of the root HTML element.

I searched some articles. Here I am sharing them with you Please have a look at them.

1. https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units

2. https://www.digitalocean.com/community/tutorials/css-rem-vs-em-units

3. https://webdesign.tutsplus.com/tutorials/comprehensive-guide-when-to-use-em-vs-rem--cms-23984

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs Review Queue Initiative

There was nothing to review code wise.
Could this one be closed out?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

2dareis2do’s picture

We should not use the on certain pseudo selectors e.g.

.toolbar .toolbar-icon::before {

see https://www.drupal.org/project/drupal/issues/3332943

I would also suggest avoiding using them on the root/html as the base font sizing can be adjusted there with media queries

e.g.

html {
    font-size: 14px;
    -webkit-text-size-adjust: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

@media only screen and (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

@media only screen and (min-width: 1200px) {
    html {
        font-size: 18px;
    }
}

According to the W3C spec the the key thing to note about rem units is::

Equal to the computed value of font-size on the root element. When specified on the font-size property of the root element, the rem units refer to the property’s initial value.

https://www.sitepoint.com/understanding-and-using-rem-units-in-css/

smustgrave’s picture

Should this be moved to documentation I wonder.

smustgrave’s picture

@alexpott what are your thoughts to #14

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.