cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <a href="https://codepen.io/jakob-e/pen/doMoML" target="_blank">
    Encode SVG SCSS</a>
            
          
!
            
              //
//  Function to create an optimized svg url
//
@function svg-url($svg){
    //
    //  Add missing namespace
    //
    @if not str-index($svg,xmlns) {
        $svg: str-replace($svg, '<svg','<svg xmlns="http://www.w3.org/2000/svg"');   
    }        
    //    
    //  Chunk up string in order to avoid 
    //  "stack level too deep" error
    //     
    $encoded:'';
    $slice: 2000;
    $index: 0;
    $loops: ceil(str-length($svg)/$slice);
    @for $i from 1 through $loops {
        $chunk: str-slice($svg, $index, $index + $slice - 1); 
        //
        //   Encode (may need a few extra replacements)
        //
        $chunk: str-replace($chunk,'"','\'');
        $chunk: str-replace($chunk,'%','%25');          
        $chunk: str-replace($chunk,'<','%3C');
        $chunk: str-replace($chunk,'>','%3E');
        $chunk: str-replace($chunk,'#','%23');   
        $chunk: str-replace($chunk,'&','%26');         
        $encoded: #{$encoded}#{$chunk};
        $index: $index + $slice; 
    }
    @return url("data:image/svg+xml,#{$encoded}");   
}
            
//  Helper function to replace characters in a string
@function str-replace($string, $search, $replace: '') {
    $index: str-index($string, $search); 
    @if $index { 
        @return str-slice($string, 1, $index - 1) + $replace + 
            str-replace(str-slice($string, $index + 
            str-length($search)), $search, $replace); 
    }
    @return $string; 
}
            
        


html {
    background-size: cover;
    background-image: svg-url('
        
        
        
      <svg width="100" height="50">
      <style type="text/css">
        .gradient { fill:url(#MyGradient); } 
      </style>
      <defs>
        <linearGradient id="MyGradient">
          <stop offset="5%" stop-color="#a60" />
          <stop offset="95%" stop-color="#FF6" />
        </linearGradient>
      </defs>
      <!-- 
          // Both fill and style seems to work  
      -->
      <rect width="100" height="50" fill="url(#MyGradient)" />
      <rect width="100" height="50" class="gradient" />
    </svg>
        
        
        
    ');
}
            
 







a {font:18px sans-serif; color:#000; float:right; }
            
          
!
999px
Loading ..................

Console