• Sign In



  • Categories

    Extension Details



    Readme

    PX-to-REM Extension for Nova

    PX to REM toggles CSS units between px and rem, or cycles them through px, rem and em, in CSS, SCSS, Sass, LESS, Vue, Svelte and HTML files.

    Commands

    Command Shortcut What it does
    PX ⇄ REM ctrl-x Toggles px ⇄ rem in the selection, or the value at the cursor
    PX ⇄ REM (Current Line) shift-ctrl-x Toggles px ⇄ rem for every value on the current line
    PX → REM → EM opt-ctrl-x Cycles px → rem → em → px in the selection, or the value at the cursor
    PX → REM → EM (Current Line) opt-shift-ctrl-x Cycles every value on the current line one step

    Run them with the shortcut, from the Editor menu or the contextual menu, or from the command palette.

    Without Option, each px value becomes rem and each rem value becomes px; em is left alone. Holding Option cycles each value one step instead: 24px → 1.5rem → 1.5em → 24px. Press it again to keep cycling. Other units such as % and vh are never changed.

    Before Command After
    16px PX ⇄ REM 1rem
    padding: 8px 1rem 0 -4px; PX ⇄ REM (Current Line) padding: 0.5rem 16px 0 -0.25rem;
    font-size: 1.5rem; PX → REM → EM font-size: 1.5em;
    margin: 8px 1rem 2em; PX → REM → EM (Current Line) margin: 0.5rem 1em 32px;

    With no selection, the cursor can be anywhere in a value or just after it, even after a trailing ;, ) or !important. The line commands keep the cursor where it was. Multiple selections and cursors are supported.

    Settings

    Base Font Size (px): the font size used for conversion (default 16), so 1rem and 1em equal this many pixels. Set it in Extensions → Extension Library → PX to REM → Settings.

    em is relative to the parent element's font size, so em values are only accurate where that matches the base font size.

    Release Notes

    Version 1.1.0

    • Converts every px/rem value in a selection, including shorthand like margin: 0 16px.
    • Keeps negative signs (-16px → -1rem).
    • Works with the cursor on a value, no selection needed, including after a trailing ;, ) or !important.
    • New PX ⇄ REM (Current Line) command (shift-ctrl-x) toggles every value on the current line.
    • New PX → REM → EM (opt-ctrl-x) and PX → REM → EM (Current Line) (opt-shift-ctrl-x) commands cycle values through px, rem and em.
    • No longer errors on selections without a px/rem value, or on uppercase units.
    • Keeps the converted text selected, including with multiple cursors.
    • New setting for the base font size (default 16px).
    • Rounds results to 4 decimal places.
    • Added LESS, Svelte and HTML support.

    Version 1.0.2

    Added support for Vue files.

    Version 1.0.1

    I'm still learning how to submit an extension.

    Version 1.0

    Initial release

    License

    MIT License

    Copyright (c) 2023 davidbdyer

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.