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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <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
Loading ..................

Console