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

              
                <div style="width:0;height:0;overflow:hidden;">
          <svg>
            <linearGradient id="btn-grad" x1="0%" y1="-20%" x2="250%" y2="20%">
              <stop offset="0%" style="stop-color:#FD8BA9;stop-opacity:1" />
              <stop offset="25%" style="stop-color:#9A94E8;stop-opacity:1" />
              <stop offset="50%" style="stop-color:#2EDBF8;stop-opacity:1" />
              <stop offset="75%" style="stop-color:#F5F1C8;stop-opacity:1"/>
              <stop offset="100%" style="stop-color:#B1E9F9;stop-opacity:1" />
            </linearGradient>
  </svg>
</div>

<svg width="0" height="0" id="morph-button-states" preserveAspectRatio="none" viewBox="0 0 105.45 53.14">
<path class="default" d="M82.7,46.1h-60c-11,0-20-9-20-20c0-11,8.9-20,20-20h60c11,0,20,9,20,20C102.7,37.1,93.8,46.1,82.7,46.1z"/>
<path class="over" d="M102.7,26.1c0,20.4-11.5,26.1-50,26.1c-37.2,0-50-6.9-50-26.1C2.7,6.9,14,0,52.7,0S102.7,7.6,102.7,26.1z"/>
<path class="down" d="M82.8,43.2c-20-2-40.2-1.9-60.1,0.2c-11,1.5-19.9-5.8-19.9-17.3c0-11.5,8.9-18.8,19.9-17.3c20,2.2,40.2,2.2,60.1,0.2 c11-1.4,19.9,5.8,19.9,17.1C102.7,37.4,93.8,44.6,82.8,43.2z"/>
</svg>


<button><span>I'm a button!</span></button>  
              
            
!

CSS

              
                body{
  padding: 6em;
  text-align: center;
}
button{
  padding: 2em;
  font-size: 20px;
  border: 0;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: relative;
  background: none;
  color: white;
  outline: 0;
  cursor: pointer;
  transition: all .1s ease-in;
  
}
button>span{
  position: relative;
}
button>svg{
  position: absolute;
  left:0;
  right:0;
  top:0;
  bottom:0;
  width: 100%;
  height: 100%;
  display: block;
  fill: url(#btn-grad);
}
button:active,
button:hover:active{
  transform: scaleX(1.1);
}
button:hover{
  transform: scaleY(1.05);
}
              
            
!

JS

              
                function MorphButton( btn, svg ){

    if( !(this instanceof MorphButton) ){
      new MorphButton( btn, svg );
      return;
    }

    function getObjects(selector){
      var objs = [];
      if( typeof selector == 'string' ){
        objs = document.querySelectorAll(selector);
      } else {
        if( 'forEach' in selector ){
          objs = selector;
        } else {
          objs = [selector];
        }
      }
      return objs;
    }

    var btnObjects = getObjects(btn),
        svgObject = getObjects(svg)[0];


    var btnStates = {
      default: svgObject.querySelector('path:nth-child(1)').getAttribute('d'),
      over: svgObject.querySelector('path:nth-child(2)').getAttribute('d'),
      down: svgObject.querySelector('path:nth-child(3)').getAttribute('d')
    };

    function initBtn(b){

      //insert an svg/path
      var s = document.createElementNS("http://www.w3.org/2000/svg", "svg");
      s.setAttribute('preserveAspectRatio',svgObject.getAttribute('preserveAspectRatio'));
      s.setAttribute('viewBox', svgObject.getAttribute('viewBox'));
      var path = document.createElementNS(s.namespaceURI,'path');
      s.appendChild(path);
      path.setAttribute('d',btnStates.default);
      s.setAttribute('fill','black');

      b.insertBefore(s,b.firstChild);

      //rig it to animations
      b.addEventListener('mouseenter',function(){
        TweenLite.to( path, .3, { morphSVG: btnStates.over, ease: Bounce.easeOut });
      });
      b.addEventListener('mouseleave',function(){
       TweenLite.to( path, .3, { morphSVG: btnStates.default, ease: Bounce.easeOut });
      });
      b.addEventListener('mousedown',function(){
        TweenLite.to( path, .3, { morphSVG: btnStates.down, ease: Bounce.easeOut });
      });
      b.addEventListener('mouseup',function(){
        TweenLite.to( path, .3, { morphSVG: btnStates.over, ease: Bounce.easeOut });
      });

    }

    //inject the svg
    btnObjects.forEach(initBtn);
};

MorphButton('button','#morph-button-states');

              
            
!
999px

Console