liveBook · Manning

Rem

As explained in Build a Website with ChatGPT

The rem unit is a CSS relative length unit measured against the root element's font size.

The CSS unit rem is a relative measurement for sizing page elements. By default, 1rem equals 16px, but it follows the default font size a browser user chooses in their settings. That makes rem-based sizing a more accessible alternative to fixed pixel measurements. section 3.4

To convert a pixel value, divide it by 16 when the default size is 16px. Common conversions are 20px = 1.25rem, 24px = 1.5rem, 32px = 2rem, and 48px = 3rem. You can use these conversions for font sizes and, when updating a page consistently, for padding and margins too. section 4.4 section 6.4

Convert a font size

Start with a CSS rule such as font-size: 20px;. To make that size relative to the browser's default font size, replace it with font-size: 1.25rem;. The intended default-size result remains 20px, while users' browser font-size preferences can affect the result. section 5.4

When customizing CSS, use rem deliberately:

  • Replace pixel-based font sizes with their rem equivalents to make text sizing relative to browser settings. section 7.4.3
  • Convert padding and margin measurements as well when you want those dimensions to scale alongside the page's text settings. section 9.6
  • Keep the number and unit together: changing 24px to 1.5rem changes both the value and the measurement unit. section 12.5

A simple next step is to scan a stylesheet for px values, convert familiar values first, and check the page afterward. Begin with text sizes, then extend the same approach to spacing where it improves the layout. section 10.8 section 13.7

How Build a Website with ChatGPT covers it

How deep it goes
Defines default pixel equivalences and conversion examples, without detailing CSS sizing mechanics beyond browser default font settings.
Examples
Uses 20px, 24px, 32px, and 48px conversions, plus an entry-text rule with font-size: 20px.
What it assumes
Assumes the ability to edit CSS numeric values while explaining rem through familiar pixel equivalents.
What you can do after
Apply it by converting pixel-based CSS font sizes and spacing values into rem measurements.
How it connects
Connects rem to CSS font-size, padding, margin, and browser settings.

Also explained in

Compare how 6 books explain rem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Website with ChatGPT. The section links point to the parts of the book it draws on.