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.

            
              <select id="type">
  <option>circle</option>
  <option>triangle</option>
</select>

<input id="customId" type="text" placeholder="custom ID">

<input id="customClass" type="text" placeholder="custom class (try red)">

<button id="update">Update</button>

<div id="output">
</div>
            
          
!
            
              svg {
  margin-top: 20px;
  width: 100px;
}

svg.red {
  fill: red;
}
            
          
!
            
              const svgs = {
    triangle: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><polygon points="24.9 0 0 50.5 49.8 50.5 24.9 0"/></svg>',
    circle: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><circle cx="25" cy="25" r="25"/></svg>'
}

function insertSvg(type, svgId = "", svgClass = "") {
    const svg = svgs[type].replace("<svg", `<svg id="${svgId}" class="${svgClass}"`);
  return svg;
}

$("#update").click(function() {
  const output = $("#output");
  const type = $("#type").val();
  const customId = $("#customId").val();
  const customClass = $("#customClass").val();
  const svgInsert = insertSvg(type, customId, customClass);
  output.empty();
  output.html(svgInsert);
});
            
          
!
999px
Loading ..................

Console