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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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



Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO


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.


Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:


Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO


                <!-- -->

<button id="save">Save as PNG</button>
<button id="print">Print Canvases as PDF</button>
Load JSON: <input type="file" id="jsonload" />
<button id='canvas2json'>Create + Save JSON as File</button>
<button id='loadJson2Canvas'>Load JSON Text Area to Canvas</button>
<button onclick="changeView(1);"><span id="viewText">(Front)</span></button>
<button onclick="dropText();">Drop Text</button>
<div style="text-align: center">
  <canvas id="canvas1" width="400" height="400"></canvas>
  <canvas id="canvas2" width="400" height="400"></canvas>
<br> JSON Generated on Save:<br>
<textarea id='myTextArea' onfocus=";" onmouseup="return false;"></textarea>


                canvas {
  border-radius: 3px;
  border: 1px solid #343A40;
  margin: auto;
  margin-top: 10px;
#myTextArea {
  width: 400px;
  height: 400px;
input[type='file'] {
  color: transparent;
  max-width: 78px;



                var mainCanvas, canvas1, canvas2, padding = 10, view = false;

function dropText() {
  var text = new fabric.IText('test');

function changeView(value) {
  if (view) {
    $viewText.textContent = "Back";
    mainCanvas = canvas1;
    $('#canvas1').parent().css('display', 'block');
    $('#canvas2').parent().css('display', 'none');
  } else {
    $viewText.textContent = "Front";
    mainCanvas = canvas2;
    $('#canvas1').parent().css('display', 'none');
    $('#canvas2').parent().css('display', 'block');
  view = !view;

// Save as image
function download(url, name) {
    href: url,
    download: name

function save() {
  var c = document.getElementById('canvas1');
  var dataURL = c.toDataURL();
  var name = 'image';
  download(dataURL, name + ".png");
  var c = document.getElementById('canvas2');
  var dataURL = c.toDataURL();
  var name = 'image';
  download(dataURL, name + ".png");


  $viewText = document.querySelector("#viewText");
  canvas1 = new fabric.Canvas('canvas1');
  canvas2 = new fabric.Canvas('canvas2');

  // canvas2json
  $("#canvas2json").click(function() {
    var json = {};
    json.c1 = canvas1.toJSON(['selectable']);
    json.c2 = canvas2.toJSON(['selectable']);
    var a = document.createElement("a");
    var file = new Blob([JSON.stringify(json)], {
      type: 'text/plain'
    a.href = URL.createObjectURL(file); = 'json.txt';;

  // load json2canvas
  $("#loadJson2Canvas").click(function() {
    var dataToLoad = JSON.parse($("#myTextArea").val());

  $('#jsonload').change(function(e) {
    var file =[0];
    if (!file) return;
    var reader = new FileReader();
    reader.onload = function(f) {
      var data =;
      data = JSON.parse(data);


  // Bleed area
  mainCanvas.on('object:moving', function(e) {
    var obj =;

    // if object is too big ignore
    if (obj.currentHeight > obj.canvas.height - padding * 2 ||
        obj.currentWidth > obj.canvas.width - padding * 2) {

    // top-left corner
    if (obj.getBoundingRect().top < padding ||
        obj.getBoundingRect().left < padding) { = Math.max(, - obj.getBoundingRect().top + padding);
      obj.left = Math.max(obj.left, obj.left - obj.getBoundingRect().left + padding);

    // bot-right corner
    if (obj.getBoundingRect().top + obj.getBoundingRect().height > obj.canvas.height - padding ||
        obj.getBoundingRect().left + obj.getBoundingRect().width > obj.canvas.width - padding) { = Math.min(,
        obj.canvas.height - obj.getBoundingRect().height + - obj.getBoundingRect().top - padding);
      obj.left = Math.min(
        obj.canvas.width - obj.getBoundingRect().width + obj.left - obj.getBoundingRect().left - padding);


  // Print
  $("#print").click(function () {
    var dataUrl1 = document.getElementById('canvas1').toDataURL();
    var dataUrl2 = document.getElementById('canvas2').toDataURL();
    var windowContent = '<!DOCTYPE html>';
    windowContent += '<html>';
    windowContent += '<head><title>Print</title>';
    windowContent += '<style>@media print{.page-break{display:block; page-break-before:always;}}</style>';
    windowContent += '</head>';
    windowContent += '<body>';
    windowContent += '<img src="' + dataUrl1 + '" onload=window.print();window.close();>';
    windowContent += '<div class="page-break"></div>';
    windowContent += '<img src="' + dataUrl2 + '" onload=window.print();window.close();>';
    windowContent += '</body>';
    windowContent += '</html>';
    var printWin ='', '', 'width=340,height=260');;


What' a functional programmer's favorite animal? A lamb, duh!