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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              <h1>preserveAspectRatio Tester</h1>

<div class="content">
  <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="100px" viewBox="0 0 100 100" preserveAspectRatio="defer">
  <path d="M49.75,8.108c-23.197,0-42.069,18.871-42.069,42.068c0,23.196,18.872,42.068,42.069,42.068  c23.195,0,42.068-18.872,42.068-42.068C91.818,26.98,72.945,8.108,49.75,8.108z M49.75,87.244c-20.44,0-37.069-16.63-37.069-37.069  c0-20.439,16.629-37.068,37.069-37.068c20.439,0,37.068,16.63,37.068,37.069C86.818,70.615,70.189,87.244,49.75,87.244z   M68.98,57.047c-10.602,10.604-27.855,10.604-38.461,0c-0.782-0.781-2.048-0.781-2.829,0c-0.781,0.781-0.781,2.049,0,2.828  c6.082,6.081,14.071,9.122,22.06,9.122c7.988,0,15.979-3.041,22.059-9.122c0.78-0.781,0.78-2.047,0-2.828  C71.027,56.266,69.762,56.266,68.98,57.047z M36.325,43.298c1.821,0,3.298-1.477,3.298-3.298s-1.477-3.298-3.298-3.298  c-1.822,0-3.298,1.477-3.298,3.298S34.503,43.298,36.325,43.298z M62.703,43.297C64.523,43.297,66,41.821,66,40  s-1.477-3.297-3.297-3.297S59.406,38.179,59.406,40S60.883,43.297,62.703,43.297z"/>
  </svg>
  
  <svg xmlns="http://www.w3.org/2000/svg" width="100px" height="200px" viewBox="0 0 100 100">
  <path d="M49.75,8.108c-23.197,0-42.069,18.871-42.069,42.068c0,23.196,18.872,42.068,42.069,42.068  c23.195,0,42.068-18.872,42.068-42.068C91.818,26.98,72.945,8.108,49.75,8.108z M49.75,87.244c-20.44,0-37.069-16.63-37.069-37.069  c0-20.439,16.629-37.068,37.069-37.068c20.439,0,37.068,16.63,37.068,37.069C86.818,70.615,70.189,87.244,49.75,87.244z   M68.98,57.047c-10.602,10.604-27.855,10.604-38.461,0c-0.782-0.781-2.048-0.781-2.829,0c-0.781,0.781-0.781,2.049,0,2.828  c6.082,6.081,14.071,9.122,22.06,9.122c7.988,0,15.979-3.041,22.059-9.122c0.78-0.781,0.78-2.047,0-2.828  C71.027,56.266,69.762,56.266,68.98,57.047z M36.325,43.298c1.821,0,3.298-1.477,3.298-3.298s-1.477-3.298-3.298-3.298  c-1.822,0-3.298,1.477-3.298,3.298S34.503,43.298,36.325,43.298z M62.703,43.297C64.523,43.297,66,41.821,66,40  s-1.477-3.297-3.297-3.297S59.406,38.179,59.406,40S60.883,43.297,62.703,43.297z"/>
  </svg>
  
  <br><br>
  
  <label for="par">align</label>
  <select id="par">
    <option value="none">none</option>
    <option value="xMinYMin">xMinYMin</option>
    <option value="xMidYMin">xMidYMin</option>
    <option value="xMaxYMin">xMaxYMin</option>
    <option value="xMinYMid">xMinYMid</option>
    <option value="xMidYMid" selected>xMidYMid</option>
    <option value="xMaxYMid">xMaxYMid</option>
    <option value="xMinYMax">xMinYMax</option>
    <option value="xMidYMax">xMidYMax</option>
    <option value="xMaxYMax">xMaxYMax</option>
  </select>
  
  <label for="mos">meetOrSlice</label>
  <select id="mos">
    <option value="meet">meet</option>
    <option value="slice">slice</option>
  </select>
    
  <p>Notes:</p>
  
  <ul>
    <li>viewBox is required or does nothing.</li>
    <li>Also can start with "defer", which apparently is only relevant to &lt;image> and otherwise ignored.</li>
    <li>If align is none, meetOrSlice does nothing</li>
    <li>I can't find docs that say xMidyMid is the default align, but it seems like it is.</li>
    <li>Sara has a <a href="https://sarasoueidan.com/demos/interactive-svg-coordinate-system/index.html">fancier one</a>, where she makes the excellent observation that meet is like background-size: contain; and slice is like cover. And the align values even have matching background-position counterparts.</li>
  </ul>
  </div>
            
          
!
            
              body {
  background: black;
  color: white;
  margin: 0;
  font-family: sans-serif;
}
h1 {
  background: #666;
  padding: 20px;
  margin: 0 0 10px 0;
}
.content {
  padding: 20px;
}

svg {
  fill: white;
  border: 2px solid #7ED950;
}

a {
  color: lightblue;
}
li {
  margin: 10px;
}
            
          
!
            
              $("select").on("change", function() {
  
  $("svg").each(function() {
    
    this.setAttribute("preserveAspectRatio", $("#par").find("option:selected").val() + " " + $("#mos").find("option:selected").val());
    
  });
  
});
            
          
!
999px
🕑 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.
Loading ..................

Console