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

              
                <h1>Web Component Style Parameter Queries</h1>

<!-- The defaults -->
<media-object>
  <img slot="img" src="https://assets.codepen.io/15542/mia.jpg" alt="Miriam speaking" height="300" width="300" />
  A Demo
  <p slot="content">
    This card is using the default parameters, with a placeholder image.
  </p>
</media-object>

<!-- Parameters applied from document CSS -->
<media-object id="miriam">
  <img slot="img" src="https://assets.codepen.io/15542/mia.jpg" alt="Miriam speaking" height="300" width="300" />
  <h2 slot="title">Miriam Suzanne</h2>
  <p slot="content">
    A person who works on the web.
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt voluptatibus libero mollitia similique, aliquam quibusdam natus repellendus expedita? Cum veniam consequatur voluptatum beatae labore architecto saepe esse sapiente, itaque unde?
  </p>
</media-object>

<!-- Parameters applied with inline CSS -->
<media-object style="--theme: fancy;">
  <img slot="img" src="https://assets.codepen.io/15542/sad.jpg" alt="A grumpy child, glaring at you" />
  <h2 slot="title">Angry Child</h2>
  <p slot="content">
    A person who is upset.
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt voluptatibus libero mollitia similique, aliquam quibusdam natus repellendus expedita? Cum veniam consequatur voluptatum beatae labore architecto saepe esse sapiente, itaque unde?
  </p>
</media-object>

<template data-element="media-object">
  <style>
    :host {
      container: media-host / inline-size;
      --theme: light;
      --media-color--dark: maroon;
      --media-color--light: snow;
      --media-grid--override: 'img'minmax(4em, 1fr) 'text'auto / 100%;
      --media-grid--default: 'img text'auto / minmax(4em, 30%) 1fr;
      --media-grid--flip: 'text img'auto / 1fr minmax(4em, 30%);
    }

    @media (prefers-color-scheme:dark) {
      :host {
        --theme: dark;
      }
    }

    article {
      background-color: var(--media-bg, var(--media-color--light, white));
      color: var(--media-text, var(--media-color--dark, black));
      display: grid;
      grid-auto-flow: dense;
      grid-gap: var(--media-gutter, var(--gutter, 1em));
      grid-template: var(--media-grid--override, var(--media-grid, var(--media-grid--default)));
      padding: var(--media-gutter, var(--gutter, 1em));
    }

    @container media-host style(--grid: flip) {
      article {
        --media-grid: var(--media-grid--flip);
      }
    }

    @container media-host style(--theme: dark) {
      article {
        --media-bg: var(--media-color--dark);
        --media-text: var(--media-color--light);
        border: medium solid teal;
      }
    }

    @container media-host style(--theme: light) {
      article {
        --media-bg: var(--media-color--light);
        --media-text: var(--media-color--dark);
        border: medium solid powderblue;
      }
    }

    @container media-host style(--theme: fancy) {
      article {
        background-image:
          linear-gradient(to bottom right, #FFC0CBBB, #EEEC, #B0E0E6BB),
          conic-gradient(red, orange, yellow, green, blue, indigo, violet, red);
        --media-text: var(--media-color--dark);
        border: medium solid mediumvioletred;
        border-top-left-radius: 70% 60%;
        border-top-right-radius: 30% 40%;
        border-bottom-right-radius: 30% 60%;
        border-bottom-left-radius: 70% 40%;
        padding: 3em;
        text-shadow: 0 1px 0 white;
      }

      [part='img'] {
        border: medium solid teal;
      }

      [part='content'] {
        background: radial-gradient(closest-side, white, transparent)
      }
    }

    @container media-host style(--media: round) {
      article {
        --media-img-radius: 100%;
      }
    }

    @container media-host (inline-size > 60ch) {
      article {
        --media-grid--override: initial;
      }
    }

    [part='img'] {
      align-self: var(--media-align, start);
      display: flex;
      justify-self: center;
      grid-column: img;
    }

    [data-default=title],
    ::slotted([slot=title]) {
      margin-bottom: 0;
    }

    /* I wish there was a way to select both in one */
    [data-default=img],
    ::slotted([slot=img]) {
      border-radius: var(--media-img-radius, 0);
      max-width: 100%;
      max-height: 100%;
      height: auto;
      overflow: hidden;
      object-fit: var(--media-fit, cover);
    }

    [data-default=img],
    ::slotted([slot=img]:not([alt])) {
      outline: medium dotted tomato;
    }

    [data-default=content] {
      font-style: italic;
      opacity: 0.5;
    }
  </style>

  <article>
    <div part="img">
      <slot name="img">
        <img data-default="img" src="https://placeimg.com/300/300/any" height="300" width="300" alt="random person placeholder" />
      </slot>
    </div>
    <div part="content">
      <slot name="title">
        <!-- use slot=title to replace the full title -->
        <!-- or use the unnamed slot to just change the text -->
        <h2 data-default="title">
          <slot>Odd McBird</slot>
        </h2>
      </slot>
      <slot name="content">
        <p data-default="content">(empty)</p>
      </slot>
    </div>
  </article>
</template>
              
            
!

CSS

              
                #miriam {
  --theme: light;
  --grid: flip;
  --media: round;
}

@layer init {
  * {
    box-sizing: border-box;
  }

  body {
    display: grid;
    gap: 1em;
    padding: 1em;
  }
}

              
            
!

JS

              
                const registerElement = (template) => {
  // copypasta from https://twitter.com/WestbrookJ/status/1369350640019922948
  customElements.define(
    template.dataset.element,
    class extends HTMLElement {
      constructor() {
        super();
        const shadowRoot = this.attachShadow({ mode: "open" }).appendChild(
          template.content.cloneNode(true)
        );
      }
    }
  );
};

document
  .querySelectorAll("template[data-element]")
  .forEach((template) => registerElement(template));

              
            
!
999px

Console