Pen Settings

HTML

CSS

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

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

              
                <html>
<head>
    <title>SVG Manipulation</title>
</head>
<body data-ng-app="SvgManipulation">
  <div data-ng-controller="IconExampleController">
  <!-- borrowing SVG from http://simpleicon.com/light-bulb-14.html -->
  <svg version="1.1" id="lightbulb" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" xml:space="preserve" style="display: none;">
    <symbol id="icon-lightbulb">
      <path id="bolt" class="displayOnHover" d="M37.5,62.5L50,46.875h12.5L37.5,62.5z M62.5,31.25L50,46.875H37.5L62.5,31.25z" />
      <path id="wave1" class="displayWhenActive" d="M22.938,62.5c0.866,1.495,0.354,3.406-1.142,4.266l-8.124,4.688c-0.488,0.287-1.025,0.422-1.557,0.422 c-1.08,0-2.13-0.562-2.71-1.562c-0.86-1.495-0.348-3.406,1.142-4.268l8.124-4.688C20.154,60.486,22.07,61.005,22.938,62.5z" />
      <path id="wave2" class="displayWhenActive" d="M15.625,50H6.25c-1.728,0-3.125-1.398-3.125-3.125c0-1.729,1.397-3.125,3.125-3.125h9.375 c1.722,0,3.125,1.396,3.125,3.125C18.75,48.602,17.347,50,15.625,50z" />
      <path id="wave3" class="displayWhenActive" d="M9.405,23.438c0.86-1.496,2.777-2.014,4.267-1.146l8.13,4.7c1.501,0.858,2.014,2.771,1.147,4.266 c-0.58,1.002-1.63,1.562-2.71,1.562c-0.531,0-1.068-0.134-1.562-0.42l-8.13-4.688C9.058,26.844,8.545,24.934,9.405,23.438z" />
      <path id="wave4" class="displayWhenActive" d="M25.415,10.547c-0.86-1.488-0.348-3.406,1.147-4.266c1.483-0.867,3.399-0.35,4.272,1.141l4.675,8.105 c0.867,1.502,0.354,3.406-1.146,4.271c-0.489,0.28-1.025,0.415-1.557,0.415c-1.08,0-2.13-0.562-2.71-1.562L25.415,10.547z" />
      <path id="wave5" class="displayWhenActive" d="M46.875,12.5V3.125C46.875,1.398,48.272,0,50,0c1.729,0,3.125,1.398,3.125,3.125V12.5 c0,1.721-1.396,3.125-3.125,3.125C48.272,15.625,46.875,14.221,46.875,12.5z" />
      <path id="wave6" class="displayWhenActive" d="M64.482,15.546l4.688-8.124c0.86-1.489,2.776-1.99,4.267-1.141c1.496,0.858,2.008,2.775,1.143,4.266 l-4.688,8.123c-0.574,1.002-1.631,1.562-2.705,1.562c-0.53,0-1.067-0.135-1.562-0.42C64.13,18.951,63.617,17.041,64.482,15.546z" />
      <path id="wave7" class="displayWhenActive" d="M77.062,31.25c-0.867-1.489-0.354-3.406,1.142-4.268l8.124-4.692c1.495-0.854,3.412-0.354,4.268,1.146 c0.865,1.495,0.354,3.406-1.143,4.272l-8.124,4.688c-0.494,0.28-1.03,0.415-1.562,0.415C78.691,32.812,77.637,32.257,77.062,31.25z" />
      <path id="wave8" class="displayWhenActive" d="M96.875,46.875c0,1.727-1.396,3.125-3.125,3.125h-9.375c-1.729,0-3.125-1.398-3.125-3.125 c0-1.729,1.396-3.125,3.125-3.125h9.375C95.479,43.75,96.875,45.146,96.875,46.875z" />
      <path id="wave9" class="displayWhenActive" d="M90.596,70.312c-0.574,1-1.631,1.562-2.705,1.562c-0.53,0-1.067-0.135-1.562-0.422l-8.13-4.693 c-1.495-0.858-2.008-2.771-1.143-4.267c0.86-1.488,2.777-2.002,4.268-1.142l8.13,4.693C90.948,66.906,91.461,68.816,90.596,70.312z" />
      <path id="bulb" d="M50,18.75c-15.533,0-28.125,12.592-28.125,28.125c0,11.018,6.396,20.459,15.625,25.073V87.5 c0,3.455,2.796,6.25,6.25,6.25c0,3.455,2.795,6.25,6.25,6.25c3.454,0,6.25-2.795,6.25-6.25c3.455,0,6.25-2.795,6.25-6.25V71.948 c9.229-4.614,15.625-14.058,15.625-25.073C78.125,31.342,65.533,18.75,50,18.75z M56.25,87.5h-12.5v-6.25h12.5V87.5z M59.705,66.357 l-3.455,1.727V75h-12.5v-6.916l-3.455-1.727c-7.507-3.754-12.17-11.22-12.17-19.482C28.125,34.814,37.939,25,50,25 c12.061,0,21.875,9.814,21.875,21.875C71.875,55.139,67.212,62.604,59.705,66.357z" />
    </symbol>
  </svg>

  <div class="preview">
    <svg class="icon" data-ng-class="{'active': lightbulbActive}" data-ng-click="lightbulbActive = !lightbulbActive" viewbox="0 0 100 100">
      <use xlink:href="#icon-lightbulb" />
    </svg>
    
    <svg class="icon" data-ng-class="{'active': lightbulbActive}" data-ng-click="lightbulbActive = !lightbulbActive" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" xml:space="preserve">
      <path id="bolt" class="displayOnHover" d="M37.5,62.5L50,46.875h12.5L37.5,62.5z M62.5,31.25L50,46.875H37.5L62.5,31.25z" />
      <path id="wave1" class="displayWhenActive" d="M22.938,62.5c0.866,1.495,0.354,3.406-1.142,4.266l-8.124,4.688c-0.488,0.287-1.025,0.422-1.557,0.422 c-1.08,0-2.13-0.562-2.71-1.562c-0.86-1.495-0.348-3.406,1.142-4.268l8.124-4.688C20.154,60.486,22.07,61.005,22.938,62.5z" />
      <path id="wave2" class="displayWhenActive" d="M15.625,50H6.25c-1.728,0-3.125-1.398-3.125-3.125c0-1.729,1.397-3.125,3.125-3.125h9.375 c1.722,0,3.125,1.396,3.125,3.125C18.75,48.602,17.347,50,15.625,50z" />
      <path id="wave3" class="displayWhenActive" d="M9.405,23.438c0.86-1.496,2.777-2.014,4.267-1.146l8.13,4.7c1.501,0.858,2.014,2.771,1.147,4.266 c-0.58,1.002-1.63,1.562-2.71,1.562c-0.531,0-1.068-0.134-1.562-0.42l-8.13-4.688C9.058,26.844,8.545,24.934,9.405,23.438z" />
      <path id="wave4" class="displayWhenActive" d="M25.415,10.547c-0.86-1.488-0.348-3.406,1.147-4.266c1.483-0.867,3.399-0.35,4.272,1.141l4.675,8.105 c0.867,1.502,0.354,3.406-1.146,4.271c-0.489,0.28-1.025,0.415-1.557,0.415c-1.08,0-2.13-0.562-2.71-1.562L25.415,10.547z" />
      <path id="wave5" class="displayWhenActive" d="M46.875,12.5V3.125C46.875,1.398,48.272,0,50,0c1.729,0,3.125,1.398,3.125,3.125V12.5 c0,1.721-1.396,3.125-3.125,3.125C48.272,15.625,46.875,14.221,46.875,12.5z" />
      <path id="wave6" class="displayWhenActive" d="M64.482,15.546l4.688-8.124c0.86-1.489,2.776-1.99,4.267-1.141c1.496,0.858,2.008,2.775,1.143,4.266 l-4.688,8.123c-0.574,1.002-1.631,1.562-2.705,1.562c-0.53,0-1.067-0.135-1.562-0.42C64.13,18.951,63.617,17.041,64.482,15.546z" />
      <path id="wave7" class="displayWhenActive" d="M77.062,31.25c-0.867-1.489-0.354-3.406,1.142-4.268l8.124-4.692c1.495-0.854,3.412-0.354,4.268,1.146 c0.865,1.495,0.354,3.406-1.143,4.272l-8.124,4.688c-0.494,0.28-1.03,0.415-1.562,0.415C78.691,32.812,77.637,32.257,77.062,31.25z" />
      <path id="wave8" class="displayWhenActive" d="M96.875,46.875c0,1.727-1.396,3.125-3.125,3.125h-9.375c-1.729,0-3.125-1.398-3.125-3.125 c0-1.729,1.396-3.125,3.125-3.125h9.375C95.479,43.75,96.875,45.146,96.875,46.875z" />
      <path id="wave9" class="displayWhenActive" d="M90.596,70.312c-0.574,1-1.631,1.562-2.705,1.562c-0.53,0-1.067-0.135-1.562-0.422l-8.13-4.693 c-1.495-0.858-2.008-2.771-1.143-4.267c0.86-1.488,2.777-2.002,4.268-1.142l8.13,4.693C90.948,66.906,91.461,68.816,90.596,70.312z" />
      <path id="bulb" d="M50,18.75c-15.533,0-28.125,12.592-28.125,28.125c0,11.018,6.396,20.459,15.625,25.073V87.5 c0,3.455,2.796,6.25,6.25,6.25c0,3.455,2.795,6.25,6.25,6.25c3.454,0,6.25-2.795,6.25-6.25c3.455,0,6.25-2.795,6.25-6.25V71.948 c9.229-4.614,15.625-14.058,15.625-25.073C78.125,31.342,65.533,18.75,50,18.75z M56.25,87.5h-12.5v-6.25h12.5V87.5z M59.705,66.357 l-3.455,1.727V75h-12.5v-6.916l-3.455-1.727c-7.507-3.754-12.17-11.22-12.17-19.482C28.125,34.814,37.939,25,50,25 c12.061,0,21.875,9.814,21.875,21.875C71.875,55.139,67.212,62.604,59.705,66.357z" />
  </svg>
    <div class="description">
      <p>On the left you will see an SVG included into the page via <strong>&lt;use&gt;</strong>.  On the right you will see an inline SVG.  Notice that the inline SVG has full functionality regarding CSS styling while the <strong>&lt;use&gt;</strong> SVG does not.  This is because the <strong>&lt;use&gt;</strong> element creates a shadow DOM which does not abide by the CSS rules of its parent.
      <p>Thanks to the new CSS psuedo selector <strong><a href="http://drafts.csswg.org/css-scoping/#shadow-pseudoelement" target="_blank">::shadow</a></strong> and the new <strong><a href="http://drafts.csswg.org/css-scoping/#deep-combinator" target="_blank">/deep/</a></strong> combinator we can bridge across the shadow DOM for style purposes.  Hover over and then click the icons to the left to change their state (the lights will share their active state).</p>
      <p>For Chrome, you will want to open your developer tools and then open the developer tool settings to enable the "Show user agent shadow DOM" option.  You may also need to enable "Experimental Web Platform Features" in <a href="chrome://flags" target="_blank">chrome://flags</a> (depending on how recent your version of Chrome is).  This will allow you to inspect the SVG in the shadow DOM to see that the CSS rules match the <strong>&lt;path&gt;</strong> elements through the <strong><a href="http://drafts.csswg.org/css-scoping/#deep-combinator" target="_blank">/deep/</a></strong> combinator, but due to a bug in the Blink engine the browser fails to compute the rules.  Oddly, if you apply a <strong>fill</strong> to the SVG element, the inner <strong>&lt;use&gt;</strong> <em>will</em> apply the fill despite having a shadow DOM which should not apply parent styles to it.</p>
      <p>Because Opera also uses the Blink rendering engine, it exhibits the same behavior.</p>
      <p>Webkit browsers (Firefox, Safari) appear not to support <strong>::shadow</strong> or <strong>/deep/</strong> correctly, but are consistent with Blink in regards to applying the parent <strong>fill</strong> property to the inner <strong>&lt;use&gt;</strong> elements which should have an isolated shadow DOM.</p>
      <p>Untested in Trident (Internet Explorer).</p>
    </div>
  </div>
</body>

</html>
              
            
!

CSS

              
                @import "compass/css3";

/* State-o-matic */
svg.icon {
  height: 50px;
  width: 50px;
  
  & .displayWhenActive, 
  & use::shadow .displayWhenActive, 
  & use /deep/ .displayWhenActive {
    display: none;
  }
  
  & .displayOnHover, 
  & use::shadow .displayOnHover, 
  & use /deep/ .displayOnHover {
    display: none;
  }
  
  &.active .displayWhenActive, 
  &.active use::shadow .displayWhenActive, 
  &.active use /deep/ .displayWhenActive {
    display: inline;
  }
  
  &:hover .displayOnHover, 
  &:hover use::shadow .displayOnHover, 
  &:hover use /deep/ .displayOnHover {
    display: inline;
  }
}

/* Colorizing */
svg.icon {
  &.active, &.active use::shadow, &.active use /deep/ {
    #bulb {
      fill: #ffff00;
    }
  }
  
  &, & use::shadow, & use /deep/ {
    #bolt {
      fill: #000000;
    }

    #wave1 {
      fill: #E98931;
    }
    #wave2 {
      fill: #EB403B;
    }
    #wave3 {
      fill: #B32E37;
    }
    #wave4 {
      fill: #6C2A6A;
    }
    #wave5 {
      fill: #5C4399;
    }
    #wave6 {
      fill: #274389;
    }
    #wave7 {
      fill: #1F5EA8;
    }
    #wave8 {
      fill: #227FB0;
    }
    #wave9 {
      fill: #2AB0C5;
    }
  }
}

/* Extra fluff */
.preview {
  display: flex;
  .icon {
    flex: 1 1 0;
  }
  .description {
    flex: 8 1 0;
  }
}
              
            
!

JS

              
                var app = angular.module('SvgManipulation', []);
app.controller('IconExampleController', function($scope){
  $scope.lightbulbActive = false;
});
              
            
!
999px

Console