🧮 Rem to Px Converter
Convert rem values from a spec or design file back to pixels using the current root font size for fixed-size contexts.
📐 工作原理与说明
px = rem × 根字号 root(rem 值乘以当前根元素 font-size)。校验:rem 与 root 均须填写且为有限数值,root 必须大于 0;缺省、0、负值或非数字都停止计算并清空旧结果,不回落 16px。判据:结果保留两位小数,同步显示「1rem = root px」基准说明,root 改变时换算同比例缩放。
把以 rem 为单位的标注或设计稿按当前根字号反算为像素,用于需要固定尺寸的场景或与设计师核对标注。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Reverse conversion | px = rem x root font size, 16 px by default | CSS Values and Units Level 4 |
| Query units | em and rem in media queries resolve against the initial size | CSS Media Queries Level 4 |
| Rounding error | keep two decimals to avoid accumulated rounding drift | CSS Values and Units Level 4 |
⚠️ 使用说明与注意事项
- px = rem × 根字号;根字号改变时同一 rem 对应的 px 会整体变化。
- 固定尺寸场景(如海报、原生 App 内嵌 WebView)常用 px;自适应网页推荐 rem。
- 结果四舍五入到 2 位小数。
📏 常用尺寸速查表(root = 16px)
| rem | px | 常见用途 |
|---|---|---|
| 0.5 | 8 | 小间距 / 描边 |
| 0.75 | 12 | 辅助文字 |
| 0.875 | 14 | 正文小字 |
| 1 | 16 | 正文基准 |
| 1.25 | 20 | 小标题 |
| 1.5 | 24 | 标题 / 间距 |
| 2 | 32 | 区块标题 |
| 3 | 48 | 大标题 |
| 4 | 64 | 页面主标题 |
若采用 62.5% 根字号方案(1rem=10px),上表 px 值 = rem × 10,例如 1.6rem→16px、2.4rem→24px。