Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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="project">
  <div class="credits">
    <h1>Made By Diabolical</h1>
  </div>
  <div class="everything-container">
    <div class="outer-container">
      <div class="container">
        <div class="section">
                  <h3 style="text-align: center;">Click the buttons to copy HTML & CSS</h3>
          <div class="button-container">
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
          </div>

          <div class="button-container">
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
          </div>

          <div class="button-container">
            <button>
              <p>Button</p>

            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
          </div>
          <div class="button-container">
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
            <button>
              <p>Button</p>
            </button>
          </div>
        </div>
      </div>
    </div>

    <div class="panel">
      <div class="title">
        <h3>Input Button Text</h3>
      </div>
      <input type="text" id="input-text" placeholder="button_name">
      <button id="random-button-text" style="background-color: #2196f3; border-radius: 4px;">Randomize</button>
      <div class="title">
        <h3>Randomize Button Styles</h3>
      </div>
      <button id="random-style-button" style="background-color: #2196f3; border-radius: 4px;">Randomize</button>
      <div style="display: flex; width: 100%; flex-direction: column; margin-top: 20px;">
        <div style="display: flex; align-items: center; justify-content: space-between; width: 100%;">
          <p>Icon Side</p>
          <label class="toggle-switch">
            <input type="checkbox" id="toggle-icon-side" />
            <span class="slider"></span>
          </label>
        </div>
        <div style="display: flex; width: 100%; align-items: center; justify-content: space-around; background-color: #2196f3; border-radius: 8px;" id="icon-side-options">
          <button style="border-radius: 8px; padding: 8px 16px;" id="left-option">Left</button>
          <button style="border-radius: 8px; padding: 8px 16px;" id="right-option">Right</button>
        </div>

        <div style="display: flex; align-items: center; justify-content: space-between; width: 100%;">
          <p>Round Button</p>
          <label class="toggle-switch">
            <input type="checkbox" id="toggle-round-button" />
            <span class="slider"></span>
          </label>
        </div>
        <div style="display: flex; justify-content: space-around; width: 100%; gap: 8px;" id="corner-inputs">
          <input type="text" style="width: inherit;" id="left-top-input">
          <input type="text" style="width: inherit;" id="right-top-input">
          <input type="text" style="width: inherit;" id="right-bottom-input">
          <input type="text" style="width: inherit;" id="left-bottom-input">
        </div>
      </div>
    </div>
              
            
!

CSS

              
                        @import url("https://fonts.googleapis.com/css2?family=Bungee&family=Inconsolata:wght@300&display=swap");

        /* Animations */
        @-webkit-keyframes bg-scrolling-reverse {
            100% {
                background-position: 50px 50px;
            }
        }

        @-moz-keyframes bg-scrolling-reverse {
            100% {
                background-position: 50px 50px;
            }
        }

        @-o-keyframes bg-scrolling-reverse {
            100% {
                background-position: 50px 50px;
            }
        }

        @keyframes bg-scrolling-reverse {
            100% {
                background-position: 50px 50px;
            }
        }

        @-webkit-keyframes bg-scrolling {
            0% {
                background-position: 50px 50px;
            }
        }

        @-moz-keyframes bg-scrolling {
            0% {
                background-position: 50px 50px;
            }
        }

        @-o-keyframes bg-scrolling {
            0% {
                background-position: 50px 50px;
            }
        }

        @keyframes bg-scrolling {
            0% {
                background-position: 50px 50px;
            }
        }

        body {
            font-family: "Poppins", sans-serif;
            background-color: #212121;
            color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100svh;
            margin: 0;
            padding: 20px;
            box-sizing: border-box;
            transition: all 0.3s ease-in-out;

            /* img size is 50x50 */
            background: url("https://cdn.discordapp.com/attachments/1124065927718252584/1124065995762442250/indir.png") repeat 0 0;
            -webkit-animation: bg-scrolling-reverse 0.92s infinite;
            /* Safari 4+ */
            -moz-animation: bg-scrolling-reverse 0.92s infinite;
            /* Fx 5+ */
            -o-animation: bg-scrolling-reverse 0.92s infinite;
            /* Opera 12+ */
            animation: bg-scrolling-reverse 0.92s infinite;
            /* IE 10+ */
            -webkit-animation-timing-function: linear;
            -moz-animation-timing-function: linear;
            -o-animation-timing-function: linear;
            animation-timing-function: linear;
        }

        h1 {
            font-family: "Bungee";
            font-weight: 100;
            text-align: left;
            line-height: 120%;
            margin: 0;
        }

        h3 {
            text-align: center;
            margin-bottom: 10px;
        }

        .everything-container {
            display: flex;
            gap: 20px;
        }

        .panel {
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            align-items: center;

            border-radius: 20px;
            overflow: hidden;
            width: 20vw;
            height: 90vh;
            box-sizing: border-box;
            padding: 20px;

            border-style: solid;
            border-width: 2px;
            border-color: #444444;
            background-color: #212121;
        }

        .panel input[type="text"] {
            display: inline-flex;
            padding: 10px;
            background-color: #363636;
            border-radius: 4px;
            border: none;
            font-family: "Bungee";
            color: var(--text-white, #fff);
            margin-bottom: 10px;
            width: -webkit-fill-available;
        }

        .panel button {
            display: inline-flex;
            padding: 20px 52px;
            justify-content: center;
            align-items: center;

            border: none;
            gap: 6px;
            font-family: "Bungee";
            line-height: 100%;

            cursor: pointer;
            width: -webkit-fill-available;
        }

        .outer-container {
            border-radius: 20px;
            overflow: hidden;
            width: 60vw;
            height: 90vh;
            box-sizing: border-box;

            border-style: solid;
            border-width: 2px;
            border-color: #444444;
        }

        .container {
            text-align: center;
            width: 100%;
            height: 100%;
            background-color: #212121;

            overflow-y: auto;
            overflow-x: hidden;

            min-width: fit-content;

            display: flex;
            gap: 20px;
            flex-direction: column;
        }

        /* This will change the width of the scrollbar */
        .container::-webkit-scrollbar {
            width: 6px;
        }

        /* This will change the color and roundness of the scrollbar "thumb" (the part you click and drag) */
        .container::-webkit-scrollbar-thumb {
            background-color: #161616;
            border-radius: 20px;
        }

        .section {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin: auto;
        }

        .project {
            display: flex;
            position: relative;
            /* New style */
        }

        .credits {
            display: flex;
            position: absolute;
            /* New style */
            top: 0;
            /* New style */
            left: 0;
            /* New style */
            height: 100%;
            /* New style */
            align-items: center;
            /* New style */
            justify-content: center;
            /* New style */
        }

        .credits h1 {
            text-align: center;
            transform: rotate(-90deg);
            /* Change from rotate to transform: rotate */
            margin-right: 50px;
            white-space: nowrap;

            position: absolute;
            /* Prevent the text from breaking into multiple lines */
        }

        .title {
            width: 100%;
            height: fit-content;
        }

        .title h2 {
            text-align: center;
            margin-bottom: 0;
        }

        .button-container {
            display: flex;
            gap: 10px;
            flex-direction: row;
            flex-wrap: wrap;

            justify-content: center;
        }

        .copy-notification {
            font-family: "Bungee", sans-serif;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: rgba(0, 0, 0, 0.8);
            color: #fff;
            padding: 10px 20px;
            border-radius: 4px;
            opacity: 0;
            animation: fade-in-out 3s ease-in-out;
        }

        @keyframes fade-in-out {

            0%,
            100% {
                opacity: 0;
            }

            10%,
            90% {
                opacity: 1;
            }
        }


        button {
            display: inline-flex;
            padding: 20px 40px;
            justify-content: center;
            align-items: center;
            background-color: #ffffff00;

            border: none;
            gap: 6px;
            font-family: "Bungee";

            cursor: pointer;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        button:hover {
            transform: scale(1.05);
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        }



        button p {
            font-family: 'Bungee';
            color: var(--text-white, #fff);
            /* Caption - Heavy */
            font-size: 12px;
            font-style: normal;
            font-weight: 400;
            line-height: 16px;

            margin: 0;
        }

/* This will change the width of the scrollbar */
        .panel::-webkit-scrollbar {
            width: 6px;
        }

        /* This will change the color and roundness of the scrollbar "thumb" (the part you click and drag) */
        .panel::-webkit-scrollbar-thumb {
            background-color: #161616;
            border-radius: 20px;
        }


        .donut-icon {
            width: 4px;
            height: 4px;
            border: 3px solid white;
            border-radius: 50%;
            background: transparent;
            position: relative;
        }

        /* Add hover animations to the toggle switch */
        .toggle-switch:hover {
            cursor: pointer;
        }

        .toggle-switch:hover .slider {
            background-color: #3e3e3e;
        }

        /* Add hover animations to the panel buttons */
        .panel button:hover {
            background-color: #1976d2;
        }

        .panel button:hover p {
            color: #fff;
        }

        .toggle-switch {
            position: relative;
            display: inline-block;
            width: 60px;
            height: 34px;
        }

        .toggle-switch input {
            display: none;
        }

        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: 0.4s;
            border-radius: 34px;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 26px;
            width: 26px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: 0.4s;
            border-radius: 50%;
        }

        input:checked+.slider {
            background-color: #2196f3;
        }

        input:checked+.slider:before {
            transform: translateX(26px);
        }

        @media only screen and (max-width: 1000px) {
            .everything-container{
                flex-direction: column;
            }

            .panel{
                width: 100%;
                height: 40svh;
                overflow: auto;
            }

            .outer-container{
                width: 100%;
                height: 50svh;
            }

            .credits{
                display: none;
            }

            .section{
                padding: 40px;
            }
        }
              
            
!

JS

              
                var cornerInputs = document.getElementById("corner-inputs");
var leftTopInput = document.getElementById("left-top-input");
var rightTopInput = document.getElementById("right-top-input");
var rightBottomInput = document.getElementById("right-bottom-input");
var leftBottomInput = document.getElementById("left-bottom-input");
var inputText = document.getElementById("input-text");
var randomizeButton = document.getElementById("random-button-text");
var randomStyleButton = document.getElementById("random-style-button");
var buttons = document.querySelectorAll(
  "button:not(#random-button-text):not(#random-style-button)"
);
var iconSideToggle = document.getElementById("toggle-icon-side");
var roundButtonToggle = document.getElementById("toggle-round-button");

var iconSideToggle = document.getElementById("toggle-icon-side");
var iconSideOptions = document.getElementById("icon-side-options");
var leftOptionButton = document.getElementById("left-option");
var rightOptionButton = document.getElementById("right-option");

window.addEventListener("load", function () {
  toggleButtonsVisibility();
  updateIconPositions();
});

iconSideToggle.addEventListener("change", function () {
  toggleButtonsVisibility();
  updateIconPositions();
});

leftOptionButton.addEventListener("click", function () {
  updateIconPositions("before");
});

rightOptionButton.addEventListener("click", function () {
  updateIconPositions("after");
});

leftTopInput.addEventListener("input", function () {
  updateButtonStyles();
});

rightTopInput.addEventListener("input", function () {
  updateButtonStyles();
});

rightBottomInput.addEventListener("input", function () {
  updateButtonStyles();
});

leftBottomInput.addEventListener("input", function () {
  updateButtonStyles();
});

buttons.forEach((button) => {
  button.addEventListener("click", function () {
    copyButtonStyles(button);
  });
});

function toggleButtonsVisibility() {
  if (iconSideToggle.checked) {
    iconSideOptions.style.display = "flex";
  } else {
    iconSideOptions.style.display = "none";
  }
}

function updateIconPositions(position) {
  var buttons = document.querySelectorAll(
    ".button-container button:not(.exclude-random)"
  );
  buttons.forEach((button) => {
    var donutIcon = button.querySelector(".donut-icon");
    if (iconSideToggle.checked) {
      if (!donutIcon) {
        donutIcon = document.createElement("div");
        donutIcon.classList.add("donut-icon");
        button.insertBefore(donutIcon, button.firstChild);
      }
      donutIcon.style.display = "block";
      if (position === "before") {
        button.insertBefore(donutIcon, button.querySelector("p"));
      } else {
        button.appendChild(donutIcon);
      }
    } else {
      if (donutIcon) {
        donutIcon.style.display = "none";
      }
    }
  });
}

function updateButtonStyles() {
  var leftTopValue = leftTopInput.value || "0";
  var rightTopValue = rightTopInput.value || "0";
  var rightBottomValue = rightBottomInput.value || "0";
  var leftBottomValue = leftBottomInput.value || "0";

  buttons.forEach((button) => {
    if (roundButtonToggle.checked) {
      button.style.borderRadius = `${leftTopValue}px ${rightTopValue}px ${rightBottomValue}px ${leftBottomValue}px`;
    } else {
      button.style.borderRadius = "4px";
    }
  });

  if (roundButtonToggle.checked) {
    cornerInputs.style.display = "flex";
  } else {
    cornerInputs.style.display = "none";
  }
}

function showCopyNotification() {
  // Create a notification element
  const notification = document.createElement("div");
  notification.textContent = "Button HTML and CSS styles have been copied!";
  notification.classList.add("copy-notification");

  // Find the section element
  const section = document.querySelector(".section");

  // Append the notification to the section
  section.appendChild(notification);

  // Remove the notification after 3 seconds
  setTimeout(() => {
    section.removeChild(notification);
  }, 3000);
}

function copyButtonStyles(button) {
  // Exclude panel buttons from copying styles
  if (button.closest(".panel")) {
    return;
  }

  // Create a new textarea element
  const textarea = document.createElement("textarea");

  // Get the button's HTML content
  const buttonHTML = button.outerHTML.trim();

  // Get the button's existing inline style
  const buttonInlineStyle = button.getAttribute("style") || "";

  // Create the combined styles for the button, button text, and donut icon
  const buttonStyles = `
                        @import url("https://fonts.googleapis.com/css2?family=Bungee&family=Inconsolata:wght@300&display=swap");

button {
            display: inline-flex;
            padding: 20px 40px;
            justify-content: center;
            align-items: center;
            background-color: #ffffff00;

            border: none;
            gap: 6px;
            font-family: "Bungee";

            cursor: pointer;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        button:hover {
            transform: scale(1.05);
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        }

        button p {
            font-family: 'Bungee';
            color: var(--text-white, #fff);
            /* Caption - Heavy */
            font-size: 12px;
            font-style: normal;
            font-weight: 400;
            line-height: 16px;

            margin: 0;
        }

        .donut-icon {
            width: 4px;
            height: 4px;
            border: 3px solid white;
            border-radius: 50%;
            background: transparent;
            position: relative;
        }
    `;

  // Set the value of the textarea to the combined button HTML and CSS styles
  textarea.value = `${buttonHTML}\n\n<style>\n${buttonStyles}\n</style>`;

  // Append the textarea to the body
  document.body.appendChild(textarea);

  // Select the contents of the textarea
  textarea.select();

  // Copy the selected content to the clipboard
  document.execCommand("copy");

  // Remove the textarea from the body
  document.body.removeChild(textarea);

  // Show the copy notification
  showCopyNotification();
}

function getRandomColor() {
  var r1 = Math.floor(Math.random() * 256);
  var g1 = Math.floor(Math.random() * 256);
  var b1 = Math.floor(Math.random() * 256);
  var r2 = Math.floor(Math.random() * 256);
  var g2 = Math.floor(Math.random() * 256);
  var b2 = Math.floor(Math.random() * 256);
  return {
    c1: { r: r1, g: g1, b: b1, rgb: "rgb(" + r1 + "," + g1 + "," + b1 + ")" },
    c2: { r: r2, g: g2, b: b2, rgb: "rgb(" + r2 + "," + g2 + "," + b2 + ")" }
  };
}

function getRandomBorderStyle() {
  var styles = [
    "none",
    "dotted",
    "dashed",
    "solid",
    "double",
    "groove",
    "ridge",
    "inset",
    "outset"
  ];
  var index = Math.floor(Math.random() * styles.length);
  return styles[index];
}

function getRandomAngle() {
  var angles = [
    "to right",
    "to bottom",
    "to left",
    "to top",
    "to bottom right",
    "to bottom left",
    "to top left",
    "to top right"
  ];
  var index = Math.floor(Math.random() * angles.length);
  return angles[index];
}

function getContrast(rgb) {
  // Calculating the perceptive luminance - human eye favors green color
  var luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
  return luminance > 0.5 ? "black" : "white";
}

function applyRandomStyles() {
  var buttons = document.querySelectorAll(
    ".button-container button:not(#random-button-text):not(#random-style-button)"
  );
  buttons.forEach((button) => {
    var colors = getRandomColor();
    var color1 = colors.c1;
    var color2 = colors.c2;
    var textColor = getContrast(color1);

    var donutIcon = button.querySelector(".donut-icon");
    if (iconSideToggle.checked) {
      if (!donutIcon) {
        donutIcon = document.createElement("div");
        donutIcon.classList.add("donut-icon");
        button.insertBefore(donutIcon, button.firstChild);
      }
      donutIcon.style.stroke = textColor;
    } else {
      if (donutIcon) {
        donutIcon.remove();
      }
    }

    var pTag = button.querySelector("p");
    if (pTag) {
      pTag.style.color = textColor;
    }

    button.style.backgroundImage = `linear-gradient(${getRandomAngle()}, ${
      color1.rgb
    }, ${color2.rgb})`;
    button.style.borderColor = Math.random() > 0.1 ? color1.rgb : "transparent"; // 10% chance of no border
    button.style.borderStyle = getRandomBorderStyle();

    if (roundButtonToggle.checked) {
      button.style.borderRadius = `${leftTopInput.value}px ${rightTopInput.value}px ${rightBottomInput.value}px ${leftBottomInput.value}px`;
    } else {
      button.style.borderRadius = "0px";
    }
  });

  if (roundButtonToggle.checked) {
    cornerInputs.style.display = "flex";
  } else {
    cornerInputs.style.display = "none";
  }
}

inputText.addEventListener("input", function () {
  buttons.forEach((button) => {
    var pTag = button.querySelector("p");
    if (pTag) {
      pTag.innerText = inputText.value;
    }
  });
});

randomizeButton.addEventListener("click", function () {
  var randomText = Math.random().toString(36).substring(7);
  buttons.forEach((button) => {
    var pTag = button.querySelector("p");
    if (pTag) {
      pTag.innerText = randomText;
    }
  });
  inputText.value = randomText;
});

randomStyleButton.addEventListener("click", function () {
  applyRandomStyles();
});

// Handle toggle switch events
iconSideToggle.addEventListener("change", function () {
  updateIconPositions();
});

roundButtonToggle.addEventListener("change", function () {
  updateButtonStyles();
});

// Initialize with random styles on page load
window.addEventListener("load", function () {
  applyRandomStyles();
});

              
            
!
999px

Console