Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <input type='text' value='Some very long text example which exceeds the lengh of this splendid input field by almost twice the size' />
              html{ height:100%; }
body{ min-height:100%; background:radial-gradient(#509DAD, #114476); background:-webkit-radial-gradient(#509DAD, #114476); }

*{ margin:0; padding:0; }

    padding:7px; margin: 20px; width:300px; font-size:26px; 
    border-radius:5px; background-color:rgba(0,0,0,0.5); border:0; color:#FFF;
    box-shadow:0 1px 1px rgba(255,255,255,0.4), 0 -1px 0 rgba(0,0,0,0.7), 0 0 15px 2px rgba(255,255,255,0.5);
    background-image: linear-gradient(0deg, #B4DB4A 100%, transparent 0%);
    background-image: -webkit-linear-gradient(0deg, #B4DB4A 100%, transparent 0%);
    background-repeat: no-repeat;
    background-position:0 100px;
/* for ugly chrome */
textarea:focus, input:focus{
    outline: none;

/* for centering only */
     input{ display:inline-block; vertical-align:middle; }
     html, body{ height:100%; text-align: center; }
     body:before{content:''; display:inline-block; height:100%; vertical-align:middle; margin-right:-0.25em; }

    $.fn.inputIndicator = function(options){
        var defaults = {
            bgPos : '30px'
        var settings = $.extend( {}, defaults, options ),
            canvas = document.createElement('canvas'), // Canvas used to check text widths.
            context = canvas.getContext('2d'),
            iCaretPos, caret, totalWidth, cssRules, font, totalTextWidth, currentTextWidth, 
            locationPercentage, textWidthRatio, getSelectionDirection;
        function getCaretPosition(oField, direction){    
            // if IE
            if( document.selection ){
                var oSel = document.selection.createRange();
                oSel.moveStart('character', -oField.value.length);
                iCaretPos = oSel.text.length;
            else if( oField.selectionStart || oField.selectionStart == '0' )
                iCaretPos = direction == 'left' ? oField.selectionStart : oField.selectionEnd;

            return iCaretPos || 0;
        function initIndicator(e){  
            if( e.keyCode == 35 )
                caret = this.value.length;
            else if( e.keyCode == 36 )
                caret = 0;
                caret = getCaretPosition(this, getSelectionDirection.direction);
            totalWidth = $(this).width();    // width of the input field
            cssRules = window.getComputedStyle(this);
            font = {
                size : parseInt(cssRules.getPropertyValue("font-size")),
                family : cssRules.getPropertyValue('font-family')
            totalTextWidth = checkTextWidth(this.value, font);
            currentTextWidth = checkTextWidth(this.value.substring(0,caret), font); // from the beginning index until current caret position
            locationPercentage = Math.floor((currentTextWidth / totalTextWidth) * 100);
            textWidthRatio = (totalWidth / totalTextWidth);
        // update the visual style of the element
        function setStyles(el){
            // check the input's value overflows
            if( textWidthRatio > 1 )
                textWidthRatio = 0;
                        'background-size' : textWidthRatio*100 + '%',
                        'background-position' : locationPercentage + '% ' + settings.bgPos
        // check a given text lengh, acording to it's size and font family
        function checkTextWidth(text, font){
            context.font = font.size + "px " + font.family;

            if( context.fillText )
                return context.measureText(text).width;
            else if( context.mozDrawText )
                return context.mozMeasureText(text);
        // find in which direction the user has selected the text, left or right
        getSelectionDirection = {
            direction : null,
            lastOffset : null,
            set : function(e){
                if( e.type == 'mousedown' )
                    getSelectionDirection.lastOffset = e.clientX;
                else if( e.type == 'mouseup' ){
                    getSelectionDirection.direction = e.clientX < getSelectionDirection.lastOffset ? 'left' : 'right';
        // make sure to initialize any input element that is inserted to the DOM after the plugin has first ran.
        $(document).bind('DOMNodeInserted', function(e){
        // init the whole thing and bind the events
            .on('mousedown mouseup keydown', this.selector, getSelectionDirection.set)
            .on('keydown focus select mouseup', this.selector, initIndicator);
        this.trigger('focus'); // make it show the first time
})(window.Zepto || window.jQuery)

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.