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 id="example-1">
  <h2><code>article:has(img)</code></h2>

  <div class="columns">
    <article data-tag="article">
      <h3>Lorem, ipsum dolor.</h3>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
    <article data-tag="article">
      <img src='https://images.unsplash.com/photo-1554692901-e16f2046918a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzQwNzc0OTg&ixlib=rb-4.0.3&q=80&w=400' alt=''>
      <h3>Lorem, ipsum dolor.</h3>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
    <article data-tag="article">
      <h3>Lorem, ipsum dolor.</h3>
      <p><img src='https://images.unsplash.com/photo-1638445533129-65aaf55fb94c?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzQwNzc5MjE&ixlib=rb-4.0.3&q=80&w=20' alt=''> Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
  </div>
</div>

<div id="example-2">
  <h2><code>article:has(> img)</code></h2>

  <div class="columns">
    <article data-tag="article">
      <h3>Lorem, ipsum dolor.</h3>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
    <article data-tag="article">
      <img src='https://images.unsplash.com/photo-1554692901-e16f2046918a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzQwNzc0OTg&ixlib=rb-4.0.3&q=80&w=400' alt=''>
      <h3>Lorem, ipsum dolor.</h3>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
    <article data-tag="article">
      <h3>Lorem, ipsum dolor.</h3>
      <p><img src='https://images.unsplash.com/photo-1638445533129-65aaf55fb94c?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzQwNzc5MjE&ixlib=rb-4.0.3&q=80&w=20' alt=''> Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
  </div>
</div>

<div id="example-3">
  <h2><code>h1:has(+ h2)</code></h2>

  <article>
    <h1 data-tag="h1">Lorem, ipsum dolor.</h1>
    <h2>Sit amet consectetur adipisicing elit.</h2>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati odit reprehenderit culpa.</p>
  </article>
  <article>
    <h1 data-tag="h1">Lorem, ipsum dolor.</h1>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati odit reprehenderit culpa.</p>
  </article>
</div>

<div id="example-4">
  <h2><code>ul:has(~ p)</code></h2>

  <div class="columns">
    <article>
      <ul data-tag="ul">
        <li>Lorem, ipsum dolor.</li>
        <li>Fugiat, officiis sint!</li>
        <li>Sit, facere ratione!</li>
      </ul>
    </article>
    <article>
      <ul data-tag="ul">
        <li>Lorem, ipsum dolor.</li>
        <li>Labore, a blanditiis!</li>
        <li>Tempora, amet consectetur.</li>
      </ul>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</p>
    </article>
  </div>
</div>

<div id="example-5">
  <h2><code>h2:has(+ h3) ~ p</code></h2>
  <div class="columns">
    <article>
      <h2 data-tag="h2">Lorem, ipsum dolor.</h2>
      <p data-tag="p">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima placeat quo omnis.</p>
      <p data-tag="p">Expedita est consectetur pariatur in, sint maiores molestiae temporibus vitae deleniti recusandae.</p>
    </article>
    <article>
      <h2 data-tag="h2">Sit amet consectetur</h2>
      <h3 data-tag="h3">Porro delectus maxime ea</h3>
      <p data-tag="p">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quod rerum quo nam.</p>
      <p data-tag="p">Corrupti incidunt similique unde iste alias nostrum sit quae natus pariatur impedit?</p>
    </article>
  </div>
</div>

<div id="example-6">
  <h2><code>p:has(a, strong, em)</code></h2>

  <div class="columns">
    <article>
      <p data-tag="p">Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque non corporis nesciunt mollitia natus. Harum.</p>
    </article>
    <article>
      <p data-tag="p">Eaque voluptatum <strong>soluta sit ipsam</strong> nihil vel optio ratione numquam magnam. Beatae amet velit odio?</p>
    </article>
  </div>
</div>

<div id="example-7">
  <h2><code>article:has(> img:first-child):has(h1 + h2)</code></h2>

  <div class="columns">
    <article data-tag="article">
      <h1 data-tag="h1">Lorem, ipsum dolor.</h1>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
    <article data-tag="article">
      <img src='https://images.unsplash.com/photo-1554692901-e16f2046918a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzQwNzc0OTg&ixlib=rb-4.0.3&q=80&w=400' alt=''>
      <h1 data-tag="h1">Lorem, ipsum dolor.</h1>
      <h2 data-tag="h2">Consectetur adipisicing elit</h2>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
    <article data-tag="article">
      <img src='https://images.unsplash.com/photo-1526137966266-60618b40bcd4?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzQwODM1Nzc&ixlib=rb-4.0.3&q=80&w=400' alt=''>
      <h1 data-tag="h1">Lorem, ipsum dolor.</h1>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
    </article>
  </div>
</div>
              
            
!

CSS

              
                #example-1 {
  article:has(img) {
    background-color: palegreen;
    padding: 0 0 2rem;

    img {
      border-radius: 0.5rem 0.5rem 0 0;
    }

    > *:not(img) {
      padding-inline: 1.5rem;
    }
  }
}

#example-2 {
  article:has(> img) {
    background-color: palegreen;
    padding: 0 0 2rem;

    img {
      border-radius: 0.5rem 0.5rem 0 0;
    }

    > *:not(img) {
      padding-inline: 1.5rem;
    }
  }
}

#example-3 {
  h1:has(+ h2) {
    font-size: 3rem;
    background-color: palegreen;

    + h2 {
      margin-block-start: 0.15em;
      color: #797979;
      font-weight: 500;
      font-style: italic;
    }
  }
}

#example-4 {
  ul:has(~ p) {
    background-color: palegreen;
    margin-block-end: 2rem;
  }
}

#example-5 {
  h2:has(+ h3) ~ p {
    background-color: palegreen;
    margin-inline-start: 2em;
  }
}

#example-6 {
  p:has(a, strong, em) {
    background-color: palegreen;
  }
}

#example-7 {
  article:has(> img:first-child):has(h1 + h2) {
    background-color: palegreen;
    padding: 0 0 2rem;

    img {
      border-radius: 0.5rem 0.5rem 0 0;
    }

    > *:not(img) {
      padding-inline: 1.5rem;
    }

    :is(h1, h2) {
      font-weight: 500;
    }

    h1 {
      font-family: Georgia, serif;
      font-size: 1.75rem;
      font-style: italic;
    }

    h2 {
      margin-block-start: 0.15em;
      font-size: 1.25rem;
    }
  }
}

:root {
  --body-bg: whitesmoke;
}

body {
  font-size: 0.9rem;
}

[id] {
  display: grid;
  place-content: center;
  gap: 4vmax;
  min-height: 100vh;
  padding: 5vmax;

  &:not(:first-child) {
    border-top: 1px dashed #797979;
  }

  *:not([id] > h2, code, .columns) {
    outline: 1px dashed #797979;
  }

  > h2 {
    text-align: center;
  }
}

[data-tag] {
  position: relative;

  &::before {
    content: attr(data-tag);
    position: absolute;
    font-family: system-ui;
    font-style: normal;
    background-color: mediumvioletred;
    letter-spacing: 0.03em;
    padding: 0.25em;
    font-size: 1.05rem;
    font-weight: 500;
    color: #fff;
    top: 0;
    left: 0;
    transform: translate(-1ch, -33%);
    border-radius: 0.25rem;
  }
}

h1 {
  font-size: 2rem;
  line-height: 1.1;
}

code {
  color: mediumvioletred;
  letter-spacing: -0.03em;
}

article {
  background-color: #fff;
  border-radius: 0.5rem;
  padding: 2rem;

  > img:first-child {
    width: 100%;
    object-fit: cover;
  }

  > * + *,
  ul li + li {
    margin-block-start: 1em;
  }
}

img {
  max-width: 100%;
  display: block;
}

.columns {
  width: min(80ch, 100vw - 2rem);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22ch, 1fr));
  gap: 2vmax;
  align-items: start;
}

              
            
!

JS

              
                
              
            
!
999px

Console