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

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.

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

              
                <h1>SVG Animated Buttons</h1>
<h2>Animate with SVG baby!</h2>
<p>Doing the SVG line animation with variable size buttons could be hard, but with a little JS, you can use any size button and get the same effect without any math on your part. Because thinking is for losers.</p>
<div class="container">
  <p>
<button type="button" class="btn btn-svg">
  <svg class="btn_svg" version="1.1" viewBox="0 0 30 20" preserveAspectRatio="none">
    <rect class="btn_svg_shape" width="30" height="20"/>
  </svg>
  <span>This is a button</span>
</button>
  </p>
  
    <p>
<button type="button" class="btn btn-svg btn-big">
  <svg class="btn_svg" version="1.1" viewBox="0 0 30 20" preserveAspectRatio="none">
    <rect class="btn_svg_shape" width="30" height="20"/>
  </svg>
  <span>This is a button</span>
</button>
  </p>
  
    <p>
<button type="button" class="btn btn-svg btn-small">
  <svg class="btn_svg" version="1.1" viewBox="0 0 30 20" preserveAspectRatio="none">
    <rect class="btn_svg_shape" width="30" height="20"/>
  </svg>
  <span>This is a button</span>
</button>
  </p>
</div>
              
            
!

CSS

              
                .btn {
  position: relative;
  overflow: hidden;
  background: none;
  padding: 1em;
  background-color: transparent;
  transition: background-color 250ms ease-in;
  font-size: 1.5rem;
  color: orange;
  .transition(background-color, color;);
  border: none;
  
  &.btn-small {
    font-size: 1rem;
  }
  &.btn-big {
    font-size: 2rem;
  }
  
  &:before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    border: 1px solid orange;
    opacity: 1;
    .transition(opacity;);
  }
  
  > span {
    position: relative;
  }
  
  .btn_svg {
    position: absolute;
    top: 0;
    left: 0;
    
    width: 100%;
    height: 100%;
  }
  .btn_svg_shape {
    stroke: orange;
    stroke-width: 2px;
    stroke-linecap: round;
    fill: transparent;
    
  }
  
  &:hover {
    transition-delay: 250ms;
    background-color: fade(black, 40%);
    color: white;
    
    &:before {
      opacity: 0;
    }
    
    .btn_svg_shape {
      .transition(stroke-dasharray, stroke-dashoffset; 500ms;);
      stroke-dashoffset: 0 !important;
      animation: 500ms pencil ease-in forwards;
    }
  }
}

/* Stroke animation. Use ems to scale :) */
@keyframes pencil{
  0% {
    stroke-width: 0.5em;
  }
  75% {
    stroke-width: 0.25em;
  }
  100%{
    stroke-width: 0.1em;
  }
}

/* Transition mixin, cause lazy */
.transition(@properties, @duration: 250ms, @easing: ease-in-out, @delay: 0){
    transition-property: @properties;
    transition-duration: @duration;
    transition-timing-function: @easing;
    transition-delay: @delay;
}

/* W00t border-box */
* {
  box-sizing: border-box;
  &:after,
  &:before {
    box-sizing: border-box;
  }
}

/* Make things perty */
html {  height: 100%;}
body { font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; background-color: #0d0d0d; color: #fff; height: 100%; padding-top: 2em; text-align: center;}
h1, h2{ margin: 0; text-transform: uppercase;text-shadow: 0 0 0.5em black;}
h2 { font-weight: 300}
input { border: 1px solid #666; background: #333; color: #fff; padding: 0.5em; box-shadow: none; outline: none !important; margin: 1em  auto; text-align: center;}
a { color: orange; text-decoration: none; transition: color 250ms ease-in-out;}
a:hover { color: yellow;}
.container { display:block; margin: 2em 0;}
p {max-width: 40em; margin: 1em auto;}
              
            
!

JS

              
                jQuery(document).ready(function(){
  
  $('.btn-svg').each(function(){
    var 
      $this = $(this),
      width = $this.outerWidth(),
      height = $this.outerHeight(),
      $svg = $this.find('svg'),
      $rect = $svg.find('rect'),
      totalPerimeter = width*2+height*2;
        
    $svg[0].setAttribute('viewBox', '0 0 '+width+' '+height);
    $rect.attr('width', width);
    $rect.attr('height', height);
    $rect.css({ 
      strokeDashoffset: totalPerimeter,
      strokeDasharray: totalPerimeter
    });
  });
  
});
              
            
!
999px

Console