Pen Settings



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


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


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.


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.


                <h1>Minimalist Container Queries</h1>

<p>By <a href="">Scott Jehl</a></p>

<p>This <code>c-q</code> custom element enables very simple "min-width" container queries, allowing you to adjust its CSS based on its own rendered width instead of viewport width.</p>


  <p>resize me!!</p>


<p>To use, set a given <code>c-q</code>'s <code>--breakpoints;</code> custom CSS property to one or more pixel-based breakpoints that the JS should be aware of, like this:</p>
<pre><code>c-q { --breakpoints: "400 600 800"; }</code></pre>
<p>One or more of these values will appear in the element's <code>data-min-width</code> attribute when they are greater or equal to the element's rendered width. You can style the element based on their presence using the <code>~=</code> attribute selector, like this: </p>
<pre><code>c-q[data-min-width~="400"] { background: green; }</code>. </p></pre>

/* demo styles */
  body {
  font-family: sans-serif;
  margin: 3vw;
code {
  padding: .3em .5em;
  font-size: 1em;
  background: #333;
  color: #fff;
  border-radius: .2em;
p {
  max-width: 45em;
  line-height: 1.5;
c-q {
  resize: both;
  display: block;
  overflow: auto;
  height: 50px;
  width: 300px;
  padding: 10px;


                c-q {
  --breakpoints: "400 600 800";
  background: tan;
c-q[data-min-width~="400"] {
  background: green;
c-q[data-min-width~="600"] {
  background: blue;
c-q[data-min-width~="800"]  {
  background: red;


                // Minimalist Container Queries
// 2020 @scottjehl, @filamentgroup / MIT License
class CQ extends HTMLElement {
  constructor() {
    this._init = this._init.bind(this);
    this._observer = new MutationObserver(this._init);
  connectedCallback() {
    if (this.children.length) {
    this._observer.observe(this, { childList: true });
  _init() {
    var self = this;
    this._rObserver = new ResizeObserver((entries) => {
      for (const entry of entries) {

  setActiveBPs(entry) {
    var bps = window.getComputedStyle("--breakpoints");
    var activeBPs = [];
    if (bps) {
      bps = bps.replace('"', "");
      bps.split(" ").forEach((bp) => {
        var bpnum = parseFloat(bp);
        if (entry.contentRect.width >= bpnum) {
    }"data-min-width", activeBPs.join(" "));
customElements.define("c-q", CQ);