View on GitHub

RFS

Bootstrap’s resizing engine responsively scales common CSS properties to better utilize available space across viewports and devices.

What is RFS?

Bootstrap’s side project RFS is a unit resizing engine which was initially developed to resize font sizes (hence its abbreviation for Responsive Font Sizes). Nowadays RFS is capable of rescaling most CSS properties with unit values like margin, padding, border-radius, or even box-shadow.

The mechanism automatically calculates the appropriate values based on the dimensions of the browser viewport. It will be compiled into calc() functions with a mix of rem and viewport units to enable the responsive scaling behavior.

Using RFS

The mixins are included in Bootstrap and are available once you include Bootstrap’s scss. RFS can also be installed standalone if needed.

Using the mixins

The rfs() mixin has shorthands for font-size, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, and padding-left. See the example below for source Sass and compiled CSS.

  1. .title {
  2. @include font-size(4rem);
  3. }
  1. .title {
  2. font-size: calc(1.525rem + 3.3vw);
  3. }
  4. @media (min-width: 1200px) {
  5. .title {
  6. font-size: 4rem;
  7. }
  8. }

Any other property can be passed to the rfs() mixin like this:

  1. .selector {
  2. @include rfs(4rem, border-radius);
  3. }

!important can also just be added to whatever value you want:

  1. .selector {
  2. @include padding(2.5rem !important);
  3. }

Using the functions

When you don’t want to use the includes, there are also two functions:

  • rfs-value() converts a value into a rem value if a px value is passed, in other cases it returns the same result.
  • rfs-fluid-value() returns the fluid version of a value if the property needs rescaling.

In this example, we use one of Bootstrap’s built-in responsive breakpoint mixins to only apply styling below the lg breakpoint.

  1. .selector {
  2. @include media-breakpoint-down(lg) {
  3. padding: rfs-fluid-value(2rem);
  4. font-size: rfs-fluid-value(1.125rem);
  5. }
  6. }
  1. @media (max-width: 991.98px) {
  2. .selector {
  3. padding: calc(1.325rem + 0.9vw);
  4. font-size: 1.125rem; /* 1.125rem is small enough, so RFS won't rescale this */
  5. }
  6. }

Extended documentation

RFS is a separate project under the Bootstrap organization. More about RFS and its configuration can be found on its GitHub repository.