Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
    <div class="wrapper" id="app">
        <section class="[ chunk ] [ flow-vertical ]">
            <h1 class="heading heading--primary"><abbr title="Pixel">PX</abbr> to REM calculator</h1>
            <p class="summary">Use this nifty tool to convert your pixel sizes to REM units.</p>

            <form action="get" class="[ form ] [ flow-vertical ]">
                <div class="form__group">
                    <label for="root_size" class="is-hidden--text">Add your root size</label>
                    <label for="root_size" aria-hidden="true" role="presentation" class="form__label">My root size is</label>
                    <input type="number" min="1" max="99" step="1" name="root_size" id="root_size" :value="rootSize" class="form__field" @input="calculate" @blur="tidyInputVal" />
                    <label for="root_size" aria-hidden="true" role="presentation" class="form__label">px.</label>
                </div>
                <div class="form__group">
                    <label for="required_size" class="is-hidden--text">Add your required pixel size</label>
                    <label for="required_size" aria-hidden="true" role="presentation" class="form__label">I want my text to be</label>
                    <input type="number" min="1" max="99" step="1" name="required_size" id="required_size" :value="pxSize" class="form__field" @input="calculate" @blur="tidyInputVal" />
                    <label for="required_size" aria-hidden="true" role="presentation" class="form__label">px.</label>
                </div>
            </form>
        </section>
        <section class="[ breathe--double-top ] [ result ]">
            Your REM size is: <b class="result__value">{{ remSize }}rem</b>
            
            <figure class="result__snippet">
                <figcaption class="is-hidden--text">CSS snippet with your new REM size</figcaption>
                <pre>
                    <code>
                        .your-element {
                            font-size: {{ remSize }}rem;
                        }
                    </code>
                </pre>
            </figure>
        </section>
        <footer class="credit">
            <p>Made with ❤️&nbsp; by <a href="https://hankchizljaw.io" rel="external">Hankchizljaw</a></p>
        </footer>
    </div>
</main>
              
            
!

CSS

              
                /*------------------------------------*\
    CSS POWERED BY STALFOS.IO

    This pen pulls in a default compilation
    of Stalfos' CSS
\*------------------------------------*/

// Type
$base-font-family: 'Quicksand', sans-serif;

// Color
$charcoal: #333;
$magenta: #de6aec;

// Metric
$gutter: 20px;
$gutter--double: 40px;


html {
    font-size: 16px;
}

body {
    background: $magenta;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: $base-font-family;
    font-size: 1.250rem;
    line-height: 1.5;
}

abbr {
    text-decoration: none;
    border: none;
    outline: none;
    cursor: help;
}

a {
    color: $charcoal;
    
    &:hover,
    &:focus {
        text-decoration: none;
    }
}

.heading {
    font-weight: 400;
    
    &--primary {
        font-size: 2.250rem;
        line-height: 1.2;
    }
}

.form {
    padding: $gutter 0 0 0;
    
    &__group {
        
        > * {
            display: inline;
        }
    }
    
    &__field {
        background: transparent;
        font-family: $base-font-family;
        padding: 2px 2px 0px 2px;
        border: none;
        font-size: 1.375rem;
        border: 1px solid transparent;
        border-bottom-color: $charcoal;
        position: relative;
        top: 1px;
        transition: all 200ms linear;
       	 
        &:focus {
            background: white;
            border-color: $charcoal;
            outline: none;
			border-radius: 3px;
        }
    }
    
    &__label {
        font-weight: 700;
        font-size: 1.375rem;
    }
}

.result {
    border-top: 1px dashed $charcoal;
    padding: $gutter--double 0 0 0;
    font-size: 1.3rem;
    
    &__value {
        display: block;
        font-size: 2.188rem;
    }
    
    &__snippet {
        
        pre {
            display: inline-block;
            padding: 16px $gutter $gutter $gutter;
            margin: $gutter 0 0 0;
            background: $charcoal;
            border-radius: 3px;
            white-space: normal;
        }
        
        code {
            tab-size: 4;
            color: white;
            font-size: 1.2rem;
            line-height: 1;
        }
    }
}

.credit {
    padding: $gutter--double 0 $gutter 0;
    font-size: 1rem;
    font-weight: 700;
    color: $charcoal;
}
              
            
!

JS

              
                const app = new Vue({
    el: '#app',
    data: {
        defaultRootSize: 16, // Used if the user leaves a field blank
        rootSize: 16,
        pxSize: 16,
        remSize: 1
    },
    methods: {
        calculate(evt) {
            let self = this;
            
            // Attempt to parse the size from the evt input
            let parsedSize = (evt.target.value.length ? parseInt(evt.target.value, 10) : self.defaultRootSize);
            
            // Find the target and set the appropriate data value
            switch(evt.target.getAttribute('name')) {
            
                case 'root_size':
                    self.rootSize = parsedSize;
                    break;
                
                case 'required_size':
                    self.pxSize = parsedSize;
                    break;
            }
            
            // Calculate rem sizw
            self.remSize = (self.pxSize / self.rootSize).toFixed(2);
            
            // Set it to 1 if something went wrong
            if(isNaN(self.remSize)) {
                self.remSize = 1;
            }
        },
        
        // Set the default root size if things get a bit larey
        tidyInputVal(evt) {
            if(!evt.target.value.length) {
                evt.target.value = self.defaultRootSize;
            }
        }
    }
});
              
            
!
999px

Console