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

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="root" data-sidebar="false" data-container="false">

  <header>
    <h1>Media vs Container</h1>
    <button data-toggle="sidebar">sidebar</button>
    <button data-toggle="container">containers</button>
  </header>
  <aside class="container">
    <article class="card">
      <img src="https://via.placeholder.com/300?text=x" width="300" height="300" alt="">
      <h2 class="title">Wireframe of a card</h2>
      <div class="content">
        <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Asperiores sunt accusamus sed, aspernatur, dolore, repellendus alias culpa aliquam eos animi molestiae neque beatae consequuntur amet praesentium voluptates libero. Consequatur, necessitatibus?</p>
      </div>
      <footer>
        <span>footer stats</span>
        <button disabled>button</button>
      </footer>
    </article>
  </aside>
  <main class="container">
    <article class="card">
      <img src="https://via.placeholder.com/300?text=x" width="300" height="300" alt="">
      <h2 class="title">Wireframe of a card</h2>
      <div class="content">
        <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Asperiores sunt accusamus sed, aspernatur, dolore, repellendus alias culpa aliquam eos animi molestiae neque beatae consequuntur amet praesentium voluptates libero. Consequatur, necessitatibus?</p>
      </div>
      <footer>
        <span>footer stats</span>
        <button disabled>button</button>
      </footer>
    </article>
  </main>

</div>
              
            
!

CSS

              
                .root {
  display: grid;
  gap: 1em;
  margin: 1em;
}

header {
  grid-column: 1 / -1;
}

header,
aside,
main {
  background: gainsboro;
  padding: 1em;
}

.card {
  --media: "small";
  font-family: "Redacted";
  display: grid;
  grid-template-columns: ;
  grid-template:
    "i" auto
    "t" auto
    "c" auto
    "f" auto
    / 1fr;
  gap: 1em;
  border: medium dotted mediumvioletred;
  padding: 1em;
}

.card > * {
  margin: 0;
}

h2::before {
  content: "(" var(--media, "@@@") ") ";
  font-family: monospace;
  font-style: normal;
  white-space: nowrap;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  grid-area: f;
}

img {
  grid-area: i;
}

@media (min-width: 30em) {
  [data-container="false"] .card {
    --media: "media > 30em";
    border-color: darkslateblue;
    grid-template:
      "i t" auto
      "i c" 1fr
      "f f" auto
      / clamp(5em, 20%, 15em) 1fr;
  }
}

@container (min-width: 30em) {
  [data-container="true"] .card {
    --media: "container > 30em";
    border-color: darkslateblue;
    grid-template:
      "i t" auto
      "i c" 1fr
      "f f" auto
      / clamp(5em, 20%, 15em) 1fr;
  }
}

@container (min-width: 45em) {
  [data-container="true"] .card {
    --media: "container > 45em";
    font-size: 1.5em;
  }
}

[data-container="true"] .container {
  container-type: inline-size;
}

@media (min-width: 45em) {
  [data-sidebar="true"] {
    grid-template-columns: clamp(20em, 30%, 25em) 1fr;
  }

  [data-sidebar="true"] aside {
    background: pink;
  }

  [data-sidebar="true"] main {
    background: powderblue;
  }
}

/* fonts n stuff */
@font-face {
  font-family: "Redacted";
  src: url("https://assets.codepen.io/15542/redacted-regular.woff2")
    format("woff2");
  font-style: normal;
  font-weight: normal;
}

@font-face {
  font-family: "Redacted";
  src: url("https://assets.codepen.io/15542/redacted-script-bold.woff2")
    format("woff2");
  font-style: italic;
  font-weight: bold;
}

@font-face {
  font-family: "Redacted";
  src: url("https://assets.codepen.io/15542/redacted-script-regular.woff2")
    format("woff2");
  font-style: italic;
  font-weight: normal;
}

@font-face {
  font-family: "Redacted";
  src: url("https://assets.codepen.io/15542/redacted-script-regular.woff2")
    format("woff2");
  font-style: italic;
  font-weight: normal;
}

img {
  width: 100%;
  height: auto;
  outline: thin solid;
}

.card {
  background: white;
  font-style: italic;
}

footer {
  color: gray;
}

p {
  font-style: italic;
  margin: 0;
}

p + P {
  margin-top: 0.75em;
}

header {
  align-items: center;
  flex-wrap: wrap;
  display: flex;
  gap: 1em;
}

h1 {
  flex: 1;
}

/* toggles */

button {
  align-items: center;
  background: teal;
  border: thin solid black;
  border-radius: 0.25em;
  color: white;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  padding: 0.25em 1em;
  position: relative;
}

button:hover,
button:focus {
  --btn-bg: var(--accent);
  --btn-text: var(--bg);
}

button:active,
button[aria-pressed="true"] {
  --btn-bg: var(--active);
  --btn-text: var(--bg);
}

button[aria-pressed="true"] {
  background: mediumvioletred;
}

button[aria-pressed="true"]::before {
  content: "✔";
  color: black;
  text-shadow: 1px 1px 0 white;
  transform: translateX(-0.5em);
  position: absolute;
  left: 0;
}

              
            
!

JS

              
                const toggle = (name) => {
  const targetName = `data-${name}`;
  const targetAttr = `[${targetName}]`;
  const target = document.querySelector(targetAttr);
  const btnAttr = `[data-toggle='${name}']`;
  const toggleBtn = document.querySelector(btnAttr);

  const targetState = () => target.getAttribute(targetName);

  const syncState = (to) => {
    const syncTo = to || targetState();
    toggleBtn.setAttribute("aria-pressed", syncTo);
  };

  const toggleIt = () => {
    const setTo = targetState() === "true" ? "false" : "true";
    target.setAttribute(targetName, setTo);
    syncState(setTo);
  };

  if (toggleBtn) {
    document.onload = syncState();
    toggleBtn.addEventListener("click", () => {
      toggleIt();
    });
  }
};

toggle("sidebar");
toggle("container");

              
            
!
999px

Console