> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/css/values/unit/relative/rem.md).

# rem

[CSS](/web/css.md) ⟩ [values](/web/css/values.md) ⟩ [relative](/web/css/values/unit/relative.md) ⟩ [units](/web/css/values/unit.md) ⟩ <mark style="color:purple;">`rem`</mark>&#x20;

{% hint style="info" %} <mark style="color:purple;">**`rem`**</mark> =  <mark style="color:yellow;">`<html>`</mark> 的 <mark style="color:blue;">`font-size`</mark>
{% endhint %}

:star:  <mark style="color:purple;">**`rem`**</mark> 是 “<mark style="color:yellow;">root em</mark>” 的縮寫，<mark style="color:blue;">`r`</mark> 指 <mark style="color:blue;">`:root`</mark> (<mark style="color:blue;">`<html>`</mark>)。

{% tabs %}
{% tab title="💾 程式" %}

<pre class="language-css"><code class="lang-css"><strong>/* :root = html */
</strong>:root { font-size: 16px; }  /* ⭐️ 定義 rem = 16px */

h1 { font-size: 2rem; }     /* 2rem = 32px */
p  { font-size: 1rem; }     /* 1rem = 16px */
</code></pre>

{% endtab %}

{% tab title="👥 相關" %}

* 用 [em](/web/css/values/unit/relative/em.md) <mark style="color:red;">會導致累積效應</mark>，用 <mark style="color:purple;">**`rem`**</mark> <mark style="color:green;">可避免</mark>這種效應。
  {% endtab %}

{% tab title="📘 手冊" %}

* MDN ⟩ [CSS values and units](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units)&#x20;
  {% endtab %}

{% tab title="📗 參考" %}

* [一次搞懂 CSS 字體單位：px、em、rem 和 %](https://www.oxxostudio.tw/articles/201809/css-font-size.html)
  {% endtab %}
  {% endtabs %}
