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.

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

            
          
!
            
              $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;
}
            
          
!
            
              // 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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console