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

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

              
                <div class="wrapper">
  <button class="test-color" id="test-color">
    Testing color
  </button><br />
  <button id="test-display">
    Testing display
  </button>
  <h1 id="test-text">Default text</h1>
  <div class="test-image-wrapper">
    <img class="test-image" id="test-image">
  </div>
  <h1 id="test-text-color">Test text color</h1>
</div>

              
            
!

CSS

              
                $colorA: #d5d41a;
$colorB: #d14d5f;
$defaultColor: #ddd;

body {
  font-family: Verdana;
}

button {
  padding: 10px;
  background-color: $defaultColor;
  border: none;
  border-radius: 5px;
  margin-bottom: 10px;
}

.wrapper {
  text-align: center;
  margin-top: 60px;
}

.test-image-wrapper {
  height: 180px;
  width: 270px;
  margin: auto;
}

img {
  height: 100%;
  width: 100%;
  display: inline-block;
}
              
            
!

JS

              
                // pure JavaScript
function testColor(colorA, colorB, elementId) {
  var randomNumber = Math.random();
  const testedElement = document.getElementById(elementId);
  if (randomNumber < 0.5) {
    testedElement.style.backgroundColor = colorA;
  } else {
    testedElement.style.backgroundColor = colorB;
  }
}

testColor('#d5d41a', '#d14d5f', 'test-color');


// jQuery:
// function testColor(colorA, colorB) {
//   var randomNumber = Math.random();
//   const testedElement = $('.test-color');
//   if (randomNumber < 0.5) {
//     testedElement.css('background-color', colorA);
//   } else {
//     testedElement.css('background-color', colorB);
//   }
// }

// testColor('#d5d41a', '#d14d5f');


function testTekst(textA, textB, elementId) {
  var randomNumber = Math.random();
  const testedElement = document.getElementById(elementId);
  if (randomNumber < 0.5) {
    testedElement.innerHTML = textA;
  } else {
    testedElement.innerHTML = textB;
  }
}

testTekst('Text A - testing text', 'Text B - testing text', 'test-text');


function testImage(imageSrcA, imageSrcB, elementId) {
  var randomNumber = Math.random();
  const testedElement = document.getElementById(elementId);
  if (randomNumber < 0.5) {
    testedElement.src = imageSrcA;
  } else {
    testedElement.src = imageSrcB;
  }
}

testImage('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcToYkhgUMQlaPMIaTByj05ha3gcX1lbV7cvdq2ByjEHWZCzXv93', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT7mHpvjE_LmXQdrYaG9FWA9NYTUHuSOD9gmtmfJNApVfpwicFY', 'test-image');

function testDisplay(elementId) {
  var randomNumber = Math.random();
  const testedElement = document.getElementById(elementId);
  if (randomNumber < 0.5) {
    testedElement.style.display = 'none';
  } else {
    testedElement.style.display = 'inline-block';
  }
}

testDisplay('test-display');

function testTextColor(colorA, colorB, elementId) {
  var randomNumber = Math.random();
  const testedElement = document.getElementById(elementId);
  if (randomNumber < 0.5) {
    testedElement.style.color = colorA;
  } else {
    testedElement.style.color = colorB;
  }
}

testTextColor('#262673', '#004d00','test-text-color');
              
            
!
999px

Console