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="container">
  <div class="buttons">
    <button>Spin</button>
    <button>Walk</button>
    <button>Run</button>
  </div>
  <tars-robot></tars-robot>
</div>

<div class="created">
  <span>Created by</span>
  <a href="https://manz.dev/"><h2>Manz.dev</h2></a>
  <p>on <a href="https://twitch.tv/ManzDev">Twitch</a> / <a href="https://youtu.be/GhRrJGJ1cFY">Youtube</a></p>
</div>
              
            
!

CSS

              
                @use postcss-nested;

@import url('https://fonts.googleapis.com/css2?family=Ramabhadra&display=swap');

body {
  background: #447;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  perspective: 900px;
}

.buttons {
  margin: 2em 0 6em;
  display: flex;
  gap: 0 15px;
}

.buttons button {
  padding: 10px;
  font-size: 16px;
  background: #1283d1;
  border: 0;
  border-radius: 10px;
  color: #eee;
  box-shadow: 0 7px 0 #0863a5, 0 8px 3px rgb(0 0 0 / 30%);
  transition: all 0.25s;
  cursor: pointer;
}

.buttons button:active {
  color: #888;
  background: #08477a;
  transform: translateY(5px);
  box-shadow: 0 2px 0 #0863a5, 0 3px 3px rgb(0 0 0 / 30%);
}

.buttons button.active {
  background: #0a5694;
  transform: translateY(3px);
  box-shadow: 0 4px 0 #0863a5, 0 5px 3px rgb(0 0 0 / 30%);
}

.created {
  background: 
    url(https://assets.codepen.io/154065/internal/avatars/users/default.png),
    linear-gradient(to bottom, #884ced, #ec1cce);
  background-size: 75px 75px, cover;
  background-repeat: no-repeat;
  position: absolute;
  top: 0;
  right: 0;
  width: 250px;
  height: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 2em;
  
  & span,
  & h2,
  & p,
  & a {
    font-family: Montserrat;
    margin: 0;
  }
  
  & a,
  & p,
  & span {
    color: #fff;    
  }
  
  & h2 {
    font-weight: 700;
    transform: translate(0, -4px);    
  }
  
  & a {
    text-decoration-color: rgba(255,255,255,0.4);
  }
  
  & a:hover {
    color: #e6e82a;
  }
}
              
            
!

JS

              
                /* TARSBlock */

class TARSBlock extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  static get styles() {
    return /* css */`
      :host {
        --width: 100px;
        --height: var(--width);
        --offset: 600px;

        width: var(--width);
        height: var(--height);
        display: block;
        position: relative;
        transform-style: preserve-3d;
        perspective: 8000px;
      }

      .face-1, .face-2, .face-5, .face-6 {
        --height: var(--offset);
      }

      .face {
        width: var(--width);
        height: var(--height);
        position: absolute;
        transform-style: preserve-3d;
        perspective: 8000px;
      }

      /* right face */
      .face-1 {
        transform-origin: 100% 0%;
        transform: rotateY(-90deg);
        background: #2C2B29;
      }

      /* left face */
      .face-2 {
        transform-origin: 0% 0%;
        transform: rotateY(90deg);
        background: #2C2B29;
      }

      /* bottom face */
      .face-3 {
        transform-origin: 100% 100%;
        transform: translateY(calc(var(--offset) - var(--width))) rotateX(90deg);
        background: #272727;
      }

      /* top face */
      .face-4 {
        transform-origin: 100% 0;
        transform: rotateX(-90deg);
        background: #aaa;
      }

      /* front face */
      .face-5 {
        background: #504C4B;
      }

      /* back face */
      .face-6 {
        transform: translateZ(calc(var(--width) * -1));
        transform-origin: 100% 100%;
        background: #444;
      }

      .face-1::before,
      .face-2::before,
      .face-5::before,
      .face-6::before {
        content: "";
        display: block;
        width: 100%;
        height: 100%;
        background: linear-gradient(to top, #fff3, #0003);
        position: absolute;
        top: 0;
        opacity: 0;
      }

      .face-1::after,
      .face-2::after,
      .face-5::after,
      .face-6::after {
        content: "";
        display: block;
        width: 100%;
        height: 100%;
        background: linear-gradient(to bottom, #fff3, #0003);
        position: absolute;
        top: 0;
        opacity: 1;
      }
    `;
  }

  debug() {
    console.log(getComputedStyle(this.shadowRoot.querySelector(".face-1")).transform);
  }

  connectedCallback() {
    this.type = this.getAttribute("type") ?? "legs";
    this.render();
    this.addEventListener("click", () => this.debug());
  }

  getFace() {
    const OPTIONS = {
      legs: "<tars-face-legs></tars-face-legs>",
      main: "<tars-face-main></tars-face-main>",
      side: "<tars-face-side></tars-face-side>"
    };

    return OPTIONS[this.type];
  }

  getSide() {
    return (this.type === "main" || this.type === "side") ? "<tars-side-side></tars-side-side>" : "";
  }

  render() {
    this.shadowRoot.innerHTML = /* html */`
    <style>${TARSBlock.styles}</style>
    <div class="face face-1">${this.getSide()}</div>
    <div class="face face-2">${this.getSide()}</div>
    <div class="face face-3 bottom"></div>
    <div class="face face-4 top"></div>
    <div class="face face-5 front">${this.getFace()}</div>
    <div class="face face-6"></div>
    `;
  }
}

customElements.define("tars-block", TARSBlock);

/* TARSFaceLegs */
class TARSFaceLegs extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  static get styles() {
    return /* css */`
      :host {
        display: flex;
        flex-direction: column;
        height: 100%;
      }

      .end {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(3, 1fr);
        width: 100%;
        height: 22%;
      }

      .end > div {
        border: 1px solid #333;
        border-top: 1px solid #aaa;
      }

      .separator {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        height: 8%;
      }

      .separator .block {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
      }

      .separator .block > div {
        border: 1px solid #333;
        border-top: 1px solid #aaa;
        border-bottom: 1px solid #aaa;
      }

      .center {
        display: grid;
        grid-template-rows: 1fr 1fr;
        height: 50%;
      }

      .center .block {
        display: grid;
        width: 100%;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: 1fr;
      }

      .center .block > div {
        border: 1px solid #333;
      }
    `;
  }

  connectedCallback() {
    this.render();
  }

  render() {
    this.shadowRoot.innerHTML = /* html */`
    <style>${TARSFaceLegs.styles}</style>
    <div class="end">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="separator">
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
    </div>
    <div class="center">
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
    </div>
    <div class="separator">
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
      <div class="block">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
    </div>
    <div class="end">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
    `;
  }
}

customElements.define("tars-face-legs", TARSFaceLegs);

/* TARSFaceMain */

class TARSFaceMain extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  static get styles() {
    return /* css */`
      :host {
        display: flex;
        flex-direction: column;
        height: 100%;
      }

      .end {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        height: 20%;
      }

      .end > div {
        border: 1px solid #333;
      }

      .black {
        background: #000;
        width: 100%;
        height: 20%;
      }

      .black.screen {
        color: #1BE820;
        font-size: 2px;
        white-space: pre;
        position: relative;
      }

      .black.screen::before {
        content: "";
        width: 100%;
        height: 20%;
        display: block;
        background: #2225;
      }

      .text {
        font-family: Ramabhadra;
        font-weight: bold;
        font-size: 40px;
        color: #b87333b4;
        text-shadow: 0 0 4px #48320B;
        transform-origin: 0 0;
        transform: rotate(-90deg);
        position: absolute;
        bottom: -16px;
        left: 7px;
        line-height: 75%;
      }

      .dots {
        letter-spacing: -5px;
      }
      
      .joke {
        background: #9CBEAB;
        width: 5px;
        height: 5px;
        position: absolute;
        top: 4px;
        left: 2px;
        opacity: 0;
        transition: opacity: 0.1s;
      }

      .joke.on {
        opacity: 1;
      }

      .center {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        height: 65%;
      }

      .center > div {
        border: 1px solid #333;
        position: relative;
      }
    `;
  }

  getTerminalText() {
    return `
      <div class="joke"></div>
      Welcome to TARS Corporation (TM) Terminal
      Copyright (C) 2984-2987, TARS Corp. Software
      OS version: 22A1-9166-69

      Initializing...
      ==================================

      Memory Test: 281474976710656B OK

      Auto-Detecting modules ... TARS "H@CK-MODULE" found!

      Searching for devices nearby...
      ==================================

      Please choose an option:

       (1) "Stellar Coffee"
       (2) "Hack the box with S4vitaar"
       (3) "CSS with ManzDev"

       What is your choice: _`;
  }

  connectedCallback() {
    this.render();
    const time = ~~(Math.random() * 5000);
    setTimeout(() => this.enableJoke(), time);
  }
  
  enableJoke() {
    const joke = this.shadowRoot.querySelector(".joke");
    joke.classList.add("on");
    setTimeout(() => joke.classList.remove("on"), 2000);
    const time = 5000 + ~~(Math.random() * 30000);
    setTimeout(() => this.enableJoke(), time);
  }

  render() {
    this.shadowRoot.innerHTML = /* html */`
    <style>${TARSFaceMain.styles}</style>
    <div class="end">
      <div></div>
      <div></div>
    </div>
    <div class="black screen">
      ${this.getTerminalText()}
    </div>
    <div class="center">
      <div>
        <div class="text">TARS</div>
      </div>
      <div>
        <div class="text dots">⠞⠁⠗⠎</div>
      </div>
      <div></div>
      <div></div>
    </div>
    <div class="black">
    </div>
    <div class="end">
      <div></div>
      <div></div>
    </div>
    `;
  }
}

customElements.define("tars-face-main", TARSFaceMain);

/* TARSFaceSide */

const PHRASES = [
  "Not enought memory",
  "The cake is a lie!",
  "File not found",
  "sudo command not found",
  "setting humor level to 60%",
  "internal error: 418 I'm a teapot",
  "ERROR 404: CSS not found",
  "Kernel panic",
  "Insert your windows installation disc and restart your computer",
  "A problem has been detected and windows has been shut down to prevent damage to your computer",
  "PEBKAC found!!!",
  "Killing humans... Please wait...",
  "H4cker not detected",
  "`rm` deprecated",
  "SQL inyected. Permission granted"
];

class TARSFaceSide extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  static get styles() {
    return /* css */`
      :host {
        display: flex;
        flex-direction: column;
        height: 100%;
      }

      .end {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        height: 20%;
      }

      .end > div {
        border: 1px solid #333;
      }

      .black {
        background: #000;
        width: 100%;
        height: 20%;
      }

      .black.screen {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        color: #1ba7e8;
        font-size: 2px;
        overflow: hidden;
        position: relative;
      }

      .black.screen .content {
        margin: 10px;
      }

      .black.screen .content::before {
        content: "";
        width: 100%;
        height: 10px;
        display: block;
        background: #000;
        position: absolute;
        top: 0;
      }

      .black.screen::after {
        content: "";
        width: 100%;
        height: 20%;
        display: block;
        background: #4445;
        position: absolute;
        top: 0;
        z-index: 5;
      }

      .text {
        font-family: Ramabhadra;
        font-weight: bold;
        font-size: 40px;
        color: #b87333da;
        text-shadow: 0 0 4px #48320B;
        transform-origin: 0 0;
        transform: rotate(-90deg);
        position: absolute;
        bottom: -16px;
        left: 8px;
        line-height: 75%;
      }

      .center {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        height: 65%;
      }

      .center > div {
        border: 1px solid #333;
        position: relative;
      }
    `;
  }

  connectedCallback() {
    this.render();
    this.screen = this.shadowRoot.querySelector(".black.screen .content");
    setTimeout(() => this.generateFakeLogs(), 50 + ~~(Math.random() * 750));
  }

  generateFakeLogs() {
    const h = ~~(Math.random() * 24);
    const m = ~~(Math.random() * 60);
    const text = PHRASES[~~(Math.random() * PHRASES.length)];
    const phrase = `[${h}:${m}] ${text}<br>`;
    this.screen.innerHTML += phrase;
    const time = 50 + ~~(Math.random() * 500);
    setTimeout(() => this.generateFakeLogs(), time);
  }

  render() {
    this.shadowRoot.innerHTML = /* html */`
    <style>${TARSFaceSide.styles}</style>
    <div class="end">
      <div></div>
      <div></div>
    </div>
    <div class="black screen">
      <div class="content">
      </div>
    </div>
    <div class="center">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="black">
    </div>
    <div class="end">
      <div></div>
      <div></div>
    </div>
    `;
  }
}

customElements.define("tars-face-side", TARSFaceSide);

/* TARSRobot */

class TARSRobot extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  static get styles() {
    return /* css */`
      .tars {
        width: 400px;
        display: flex;
        justify-content: center;
        transform: rotateY(20deg);
        transform-style: preserve-3d;
        perspective: 8000px;
        gap: 4px;
      }

      tars-block {
        height: 600px;
      }

      tars-block:nth-child(1) { z-index: 4; }
      tars-block:nth-child(2) { z-index: 3; }
      tars-block:nth-child(3) { z-index: 2; }
      tars-block:nth-child(4) { z-index: 1; }

      /* Walk animation */
      :host(.walk) tars-block {
        transform-origin: 100% 50%;
        animation: walk 1s cubic-bezier(0.6, 0, 0.4, 1) infinite alternate;
      }

      :host(.walk) tars-block:nth-child(2),
      :host(.walk) tars-block:nth-child(3) {
        animation-direction: alternate-reverse;
      }

      @keyframes walk {
        0% { transform: rotateX(15deg); }
        100% { transform: rotateX(-15deg); }
      }

      /* Run animation */
      :host(.run) tars-block {
        transform-origin: 100% 20%;
        animation: run 2s ease-in-out infinite alternate;
      }

      :host(.run) tars-block:nth-child(1) {
        animation-delay: 0s;
      }

      :host(.run) tars-block:nth-child(2) {
        animation-delay: 0.5s;
      }

      :host(.run) tars-block:nth-child(3) {
        animation-delay: 1.5s;
      }

      :host(.run) tars-block:nth-child(4) {
        animation-delay: 2s;
      }

      @keyframes run {
        0%, 100% { transform: rotateX(0); }
        33% { transform: rotateX(15deg); }
        66% { transform: rotateX(-15deg); }
      }

      /* Spin Animation */
      :host(.spin) .tars {
        animation: spin 5s linear infinite;
      }

      @keyframes spin {
        0% { transform: rotateY(0); }
        100% { transform: rotateY(360deg);}
      }
    `;
  }

  connectedCallback() {
    this.render();
  }

  render() {
    this.shadowRoot.innerHTML = /* html */`
    <style>${TARSRobot.styles}</style>
    <div class="tars">
      <tars-block class="block-1" type="legs"></tars-block>
      <tars-block class="block-2" type="main"></tars-block>
      <tars-block class="block-3" type="side"></tars-block>
      <tars-block class="block-4" type="legs"></tars-block>
    </div>`;
  }
}

customElements.define("tars-robot", TARSRobot);

/* TARSSideSide */
class TARSSideSide extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  static get styles() {
    return /* css */`
      :host {
        display: flex;
        flex-direction: column;
        height: 100%;
      }

      .end {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        height: 20%;
      }

      .end > div {
        border: 1px solid #333;
      }

      .black {
        background: #000;
        width: 100%;
        height: 20%;
      }

      .black.screen {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        color: #1ba7e8;
        font-size: 2px;
        overflow: hidden;
        position: relative;
      }

      .black.screen .content {
        margin: 10px;
      }

      .black.screen .content::before {
        content: "";
        width: 100%;
        height: 10px;
        display: block;
        background: #000;
        position: absolute;
        top: 0;
      }

      .black.screen::after {
        content: "";
        width: 100%;
        height: 20%;
        display: block;
        background: #4445;
        position: absolute;
        top: 0;
        z-index: 5;
      }

      .center {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        height: 65%;
      }

      .center > div {
        border: 1px solid #333;
        position: relative;
      }
    `;
  }

  connectedCallback() {
    this.render();
    this.screen = this.shadowRoot.querySelector(".black.screen .content");
  }

  render() {
    this.shadowRoot.innerHTML = /* html */`
    <style>${TARSSideSide.styles}</style>
    <div class="end">
      <div></div>
      <div></div>
    </div>
    <div class="black screen">
      <div class="content">
      </div>
    </div>
    <div class="center">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="black">
    </div>
    <div class="end">
      <div></div>
      <div></div>
    </div>
    `;
  }
}

/* Main */

customElements.define("tars-side-side", TARSSideSide);

const tars = document.querySelector("tars-robot");
const [spinButton, walkButton, runButton] = document.querySelectorAll("button");

spinButton.addEventListener("click", () => {
  spinButton.classList.toggle("active");
  tars.classList.toggle("spin");
});
walkButton.addEventListener("click", () => {
  walkButton.classList.toggle("active");
  tars.classList.toggle("walk");
});
runButton.addEventListener("click", () => {
  runButton.classList.toggle("active");
  tars.classList.toggle("run");
});
              
            
!
999px

Console