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="controls">
  <fieldset>
    <legend>Position</legend>
    <div>
      <input type="checkbox" class="tl" checked />
      <input type="checkbox" class="tc" />
      <input type="checkbox" class="tr" checked />
    </div>    
    <div>
      <input type="checkbox" class="cl" />
      <input type="checkbox" class="cc" />
      <input type="checkbox" class="cr" />
    </div>    
    <div>
      <input type="checkbox" class="bl" />
      <input type="checkbox" class="bc" />
      <input type="checkbox" class="br" />
    </div>    
  </fieldset>
  <fieldset>
    <legend>inset-inline</legend>
    <div><label>
      <input type="radio" name="inset-inline" class="inset-inline-center" checked />
      auto
    </label></div>
    <div><label>
      <input type="radio" name="inset-inline" class="inset-inline-0" />
      0
    </label></div>
    <div><label>
      <input type="radio" name="inset-inline" class="inset-inline-25" />
      25%
    </label></div>
    <div><label>
      <input type="radio" name="inset-inline" class="inset-inline-50" />
      50%
    </label></div>
  </fieldset>
  <fieldset>
    <legend>inset-block</legend>
    <div><label>
      <input type="radio" name="inset-block" class="inset-block-center" checked />
      auto
    </label></div>
    <div><label>
      <input type="radio" name="inset-block" class="inset-block-0" />
      0
    </label></div>
    <div><label>
      <input type="radio" name="inset-block" class="inset-block-25" />
      25%
    </label></div>
    <div><label>
      <input type="radio" name="inset-block" class="inset-block-50" />
      50%
    </label></div>
  </fieldset>

  <fieldset>
    <legend>margin</legend>
    <div><label>
      <input type="radio" name="margin" class="margin-0" />
      0
    </label></div>
    <div><label>
      <input type="radio" name="margin" class="margin-1" />
      1em
    </label></div>
    <div><label>
      <input type="radio" name="margin" class="margin-2" checked />
      2em
    </label></div>
  </fieldset>
  <fieldset class="code-placeholder">
    <legend>code</legend>
  </fieldset>
  
</div>

<div class="root" style="--is: --root;">
  <div class="resizer" id="resizer"></div>
  <div class="anchor" anchor="resizer" style="--is: --anchor;">
    anchor
  </div>
</div>

<div style="--for: --anchor; --context: --root;">
  <div class="outline outline-top"></div>
  <div class="outline outline-bottom"></div>
  <div class="outline outline-left"></div>
  <div class="outline outline-right"></div>
</div>

<div
  class="popover"
  style="
    --is: --popover;
    --for: --anchor;
    --context: --root;
  "
>
  <div class="popover-content">
    <div contenteditable>this is a popover</div>
  </div>

  <div class="tether tether-center-x"></div>
  <div class="tether tether-center-y"></div>
  <div class="tether tether-corner"><span>tether</span></div>
</div>


<dialog open id="fallback">
  <p>Your browser does not support anchor positioning.</p>
  <p>To play with this demo, open it in Chrome Canary with the “Experimental web platform features” feature flag on.</p>
  <p>Here is a screen recording of this demo:</p>
  <video controls muted playsinline preload="none" poster="https://kizu.dev/videos/inset-area.jpg">
    <source src="https://kizu.dev/videos/inset-area.mp4" type="video/mp4">
    Sorry, your browser doesn’t support embedded videos. You can <a href="https://kizu.dev/videos/inset-area.mp4">download it</a>.
  </video>  
  <p><button type="button" onclick="fallback.close()">Close this dialog</button></p>
</dialog>


              
            
!

CSS

              
                /* The code is a mess! */

.anchor {
  position: absolute;
  top: anchor(bottom);
  left: anchor(right);
  width: 20em;
  height: 15em;
  overflow: hidden;
  resize: both;
  anchor-name: var(--is);
}

/* Move it to the content part for proper tethering */
.popover-content {
  /* Would need to be unique to be able to connect it to both elements */
  anchor-name: var(--is);
  max-width: 100%;
  min-width: 0;
  max-height: 100%;
  min-height: 0;
  pointer-events: auto;
}

.popover {
  position: absolute;
  position-anchor: var(--for);
  transition: all 1s;
  pointer-events: none;
  
  /* Space toggles ftw https://kizu.dev/cyclic-toggles/ */
  --inset-area:
    var(--center-x)
    var(--center-y);
  --left: var(--inset-area,);
  --right: var(--inset-area,);
  --top: var(--inset-area,);
  --bottom: var(--inset-area,);
  --center-x: var(--inset-area,);
  --center-y: var(--inset-area,);
  --all-x: var(--inset-area,);
  --all-y: var(--inset-area,);

  --inset-left: var(--inset-inline, var(--inset, 0));
  --inset-top: var(--inset-block, var(--inset, 0));
  --inset-right: var(--inset-inline, var(--inset, 0));
  --inset-bottom: var(--inset-block, var(--inset, 0));
  

  /* anchor-center */
  --adjust-x: 0px;
  --adjust-y: 0px;
  --anchor-center: min(anchor(inside), max(0px, (anchor(inside) - anchor(var(--context) inside)) - (anchor(var(--context) outside) - anchor(outside))));

  --same-side: anchor(var(--context) inside) +
    (anchor(inside) - anchor(var(--context) inside));
  --start-center-side: anchor(inside) + 
    (anchor(outside) - anchor(inside));
  --start-full-side: anchor(outside) +
    (anchor(var(--context) outside) - anchor(outside));
  --end-center-side: anchor(inside) - 
    (anchor(inside) - anchor(outside));
  --end-full-side: anchor(outside) -
    (anchor(outside) - anchor(var(--context) outside));

  --top-center-no-top:
    var(--top)
    var(--center-y, var(--start-center-side));
  --top-bottom-no-center:
    var(--center-y)
    var(--bottom, var(--start-full-side));
  top: calc(
    var(--adjust-y) + 
    var(--top, var(--same-side))
    var(--top-bottom-no-center,)
    var(--top-center-no-top,)
    var(--all-y, var(--same-side))
    * var(--inset-top)
  );
  --bottom-top-no-center:
    var(--center-y)
    var(--top, var(--end-full-side));
  --bottom-center-no-bottom:
    var(--bottom)
    var(--center-y, var(--end-center-side));
  bottom: calc(
    var(--adjust-y) + 
    var(--bottom-top-no-center,)
    var(--bottom, var(--same-side))
    var(--bottom-center-no-bottom,)
    var(--all-y, var(--same-side))
    * var(--inset-bottom)
  );
  --left-center-no-left:
    var(--left)
    var(--center-x, var(--start-center-side));
  --left-right-no-center:
    var(--center-x)
    var(--right, var(--start-full-side));
  left: calc(
    var(--adjust-x) +
    var(--left, var(--same-side))
    var(--left-right-no-center,)
    var(--left-center-no-left,)
    var(--all-x, var(--same-side))
    * var(--inset-left)
  );
  --right-left-no-center:
    var(--center-x)
    var(--left, var(--end-full-side));
  --right-center-no-right:
    var(--right)
    var(--center-x, var(--end-center-side));
  right: calc(
    var(--adjust-x) + 
    var(--right-left-no-center,)
    var(--right, var(--same-side))
    var(--right-center-no-right,)
    var(--all-x, var(--same-side))
    * var(--inset-right)
  );
  
}

.tether {
  pointer-events: none;
  position: fixed;
  position-anchor: var(--for);
}

.tether-center-x {
  anchor-name: --center-x;
  inset-block: min(anchor(outside), anchor(var(--is) outside));
  inset-inline: max(anchor(inside), anchor(var(--is) inside));
}
.tether-center-y {
  anchor-name: --center-y;
  inset-block: max(anchor(inside), anchor(var(--is) inside));
  inset-inline: min(anchor(outside), anchor(var(--is) outside));
}

.tether-corner {
  border: 4px dotted;
  position-anchor: var(--for);
  inset: min(anchor(--center-x inside), anchor(--center-y inside));
}

/* Configurable */

body:has(.inset-inline-0:checked) .popover {
  --inset-inline: 0;
  --adjust-x: 0px !important;
}

body:has(.inset-inline-25:checked) .popover {
  --inset-inline: 0.25;
  --adjust-x: 0px !important;
}

body:has(.inset-inline-50:checked) .popover {
  --inset-inline: 0.5;
  --adjust-x: 0px !important;
}

body:has(.inset-block-0:checked) .popover {
  --inset-block: 0;
  --adjust-y: 0px !important;
}

body:has(.inset-block-25:checked) .popover {
  --inset-block: 0.25;
  --adjust-y: 0px !important;
}

body:has(.inset-block-50:checked) .popover {
  --inset-block: 0.5;
  --adjust-y: 0px !important;
}

body:has(.margin-0:checked) .popover {
  margin: 0;
}

body:has(.margin-1:checked) .popover {
  margin: 1em
}

body:has(.margin-2:checked) .popover {
  margin: 2em;
}


/* 1x1 */
body:has(.tl:checked) .popover {
  --code: 'top / left';
  --inset-area: var(--top) var(--left);
  --align: var(--align-bottom) var(--align-right);
}

body:has(.tc:checked) .popover {
  --code: 'top / center';
  --inset-area: var(--top) var(--center-x);
  --align: var(--align-bottom) var(--align-center-x);
}

body:has(.tr:checked) .popover {
  --code: 'top / right';
  --inset-area: var(--top) var(--right);
  --align: var(--align-bottom) var(--align-left);
}

body:has(.cl:checked) .popover {
  --code: 'center / left';
  --inset-area: var(--center-y) var(--left);
  --align: var(--align-center-y) var(--align-right);
}

body:has(.cr:checked) .popover {
  --code: 'center / right';
  --inset-area: var(--center-y) var(--right);
  --align: var(--align-center-y) var(--align-left);
}

body:has(.bl:checked) .popover {
  --code: 'bottom / left';
  --inset-area: var(--bottom) var(--left);
  --align: var(--align-top) var(--align-right);
}

body:has(.bc:checked) .popover {
  --code: 'bottom / center';
  --inset-area: var(--bottom) var(--center-x);
  --align: var(--align-top) var(--align-center-x);
}

body:has(.br:checked) .popover {
  --code: 'bottom / right';
  --inset-area: var(--bottom) var(--right);
  --align: var(--align-top) var(--align-left);
}


/* 1x2 */
body:has(.tl:checked):has(.tc:checked) .popover {
  --code: 'top / left center';
  --inset-area: var(--top) var(--left) var(--center-x);
  --align: var(--align-bottom) var(--align-center-x);
}

body:has(.tr:checked):has(.tc:checked) .popover {
  --code: 'top / right center';
  --inset-area: var(--top) var(--right) var(--center-x);
  --align: var(--align-bottom) var(--align-center-x);
}

body:has(.bl:checked):has(.bc:checked) .popover {
  --code: 'bottom / left center';
  --inset-area: var(--bottom) var(--left) var(--center-x);
  --align: var(--align-top) var(--align-center-x);
}

body:has(.br:checked):has(.bc:checked) .popover {
  --code: 'bottom / right center';
  --inset-area: var(--bottom) var(--right) var(--center-x);
  --align: var(--align-top) var(--align-center-x);
}

body:has(.tl:checked):has(.cl:checked) .popover {
  --inset-area: var(--top) var(--center-y) var(--left);
  --code: 'top center / left';
  --align: var(--align-center-y) var(--align-right);
}

body:has(.tr:checked):has(.cr:checked) .popover {
  --inset-area: var(--top) var(--center-y) var(--right);
  --code: 'top center / right';
  --align: var(--align-center-y) var(--align-left);
}

body:has(.bl:checked):has(.cl:checked) .popover {
  --inset-area: var(--bottom) var(--center-y) var(--left);
  --code: 'bottom center / left';
  --align: var(--align-center-y) var(--align-right);
}

body:has(.br:checked):has(.cr:checked) .popover {
  --inset-area: var(--bottom) var(--center-y) var(--right);
  --code: 'bottom center / right';
  --align: var(--align-center-y) var(--align-left);
}

/* cc */
body:has(.tc:checked):has(.cc:checked) .popover {
  --inset-area: var(--top) var(--center-y) var(--center-x);
  --code: 'top center / center';
  --align: var(--align-center-y) var(--align-center-x);
}
body:has(.bc:checked):has(.cc:checked) .popover {
  --inset-area: var(--bottom) var(--center-y) var(--center-x);
  --code: 'bottom center / center';
  --align: var(--align-center-y) var(--align-center-x);
}
body:has(.cl:checked):has(.cc:checked) .popover {
  --inset-area: var(--center-y) var(--left) var(--center-x);
  --code: 'center / left center';
  --align: var(--align-center-y) var(--align-center-x);
}
body:has(.cr:checked):has(.cc:checked) .popover {
  --inset-area: var(--center-y) var(--right) var(--center-x);
  --code: 'center / right center';
  --align: var(--align-center-y) var(--align-center-x);
}


/* 2x2 */
body:has(.tc:checked):has(.cl:checked) .popover,
body:has(.tl:checked):has(.cc:checked) .popover {
  --inset-area: var(--top) var(--center-y) var(--left) var(--center-x);
  --code: 'top center / left center';
  --align: var(--align-center-y) var(--align-center-x);
}

body:has(.tc:checked):has(.cr:checked) .popover,
body:has(.tr:checked):has(.cc:checked) .popover {
  --inset-area: var(--top) var(--center-y) var(--right) var(--center-x);
  --code: 'top center / right center';
  --align: var(--align-center-y) var(--align-center-x);
}

body:has(.bc:checked):has(.cl:checked) .popover,
body:has(.bl:checked):has(.cc:checked) .popover {
  --inset-area: var(--bottom) var(--center-y) var(--left) var(--center-x);
  --code: 'bottom center / left center';
  --align: var(--align-center-y) var(--align-center-x);
}

body:has(.bc:checked):has(.cr:checked) .popover,
body:has(.br:checked):has(.cc:checked) .popover {
  --inset-area: var(--bottom) var(--center-y) var(--right) var(--center-x);
  --code: 'bottom center / right center';
  --align: var(--align-center-y) var(--align-center-x);
}


/* 1x3 */
body:has(.tl:checked):has(.tr:checked) .popover {
  --inset-area: var(--top) var(--all-x);
  --code: 'top / all';
  --align: var(--align-bottom) var(--align-center-x);
  --adjust-x: var(--anchor-center);
}
body:has(.bl:checked):has(.br:checked) .popover {
  --inset-area: var(--bottom) var(--all-x);
  --code: 'bottom / all';
  --align: var(--align-top) var(--align-center-x);
  --adjust-x: var(--anchor-center);
}
body:has(.tl:checked):has(.bl:checked) .popover {
  --inset-area: var(--all-y) var(--left);
  --code: 'all / left';
  --align: var(--align-center-y) var(--align-right);
  --adjust-y: var(--anchor-center);
}
body:has(.tr:checked):has(.br:checked) .popover {
  --inset-area: var(--all-y) var(--right);
  --code: 'all / right';
  --align: var(--align-center-y) var(--align-left);
  --adjust-y: var(--anchor-center);
}

/* center 1x3 */
body:has(.tc:checked):has(.bc:checked) .popover {
  --inset-area: var(--all-y) var(--center-x);
  --code: 'all / center';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-y: var(--anchor-center);
}

body:has(.cl:checked):has(.cr:checked) .popover {
  --inset-area: var(--center-y) var(--all-x);
  --code: 'center / all';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-x: var(--anchor-center);
}


/* 2/3 */
body:has(.cl:checked):has(.tr:checked) .popover,
body:has(.cr:checked):has(.tl:checked) .popover,
body:has(.cl:checked):has(.cr:checked):has(.tc:checked) .popover,
body:has(.tl:checked):has(.tr:checked):has(.cc:checked) .popover {
  --inset-area: var(--top) var(--center-y) var(--all-x);
  --code: 'top center / all';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-x: var(--anchor-center);
}

body:has(.cl:checked):has(.br:checked) .popover,
body:has(.cr:checked):has(.bl:checked) .popover,
body:has(.cl:checked):has(.cr:checked):has(.bc:checked) .popover,
body:has(.bl:checked):has(.br:checked):has(.cc:checked) .popover {
  --inset-area: var(--bottom) var(--center-y) var(--all-x);
  --code: 'bottom center / all';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-x: var(--anchor-center);
}

body:has(.tc:checked):has(.bl:checked) .popover,
body:has(.bc:checked):has(.tl:checked) .popover,
body:has(.tc:checked):has(.bc:checked):has(.cl:checked) .popover,
body:has(.tl:checked):has(.bl:checked):has(.cc:checked) .popover {
  --inset-area: var(--all-y) var(--left) var(--center-x);
  --code: 'all / left center';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-y: var(--anchor-center);
}

body:has(.tc:checked):has(.br:checked) .popover,
body:has(.bc:checked):has(.tr:checked) .popover,
body:has(.tc:checked):has(.bc:checked):has(.cr:checked) .popover,
body:has(.tr:checked):has(.br:checked):has(.cc:checked) .popover {
  --inset-area: var(--all-y) var(--right) var(--center-x);
  --code: 'all / right center';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-y: var(--anchor-center);
}


/* 3x3 */
body:has(.tl:checked):has(.br:checked) .popover,
body:has(.tr:checked):has(.bl:checked) .popover,
body:has(:is(.tl, .tc, .tr):checked):has(:is(.cl, .cc, .cr):checked):has(:is(.bl, .bc, .br):checked):has(:is(.tl, .cl, .bl):checked):has(:is(.tr, .cr, .br):checked) .popover,
body:has(:is(.tl, .cl, .bl):checked):has(:is(.tc, .cc, .bc):checked):has(:is(.tr, .cr, .br):checked):has(:is(.tl, .tc, .tr):checked):has(:is(.bl, .bc, .br):checked) .popover{
  --inset-area: var(--all-y) var(--all-x);
  --code: 'all / all';
  --align: var(--align-center-y) var(--align-center-x);
  --adjust-x: var(--anchor-center);
  --adjust-y: var(--anchor-center);
}




/* Presentational Styles */

body {
  margin: 0;
  font-family: sans-serif;
}

.anchor,
.popover-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #FFF;
  border-radius: 1em;
}

.anchor {
  background: #f7b722;
  
}
.popover {
  display: grid;
  --align: var(--align-center-y) var(--align-center-x);
  --align-center-y: var(--align,);
  --align-center-x: var(--align,);
  --align-left: var(--align,);
  --align-right: var(--align,);
  --align-top: var(--align,);
  --align-bottom: var(--align,);
  --left-align:
    var(--align-left, 0fr)
    var(--align-center-x, 1fr)
    var(--align-right, 1fr);
  --right-align:
    var(--align-left, 1fr)
    var(--align-center-x, 1fr)
    var(--align-right, 0fr);
  --top-align:
    var(--align-top, 0fr)
    var(--align-center-y, 1fr)
    var(--align-bottom, 1fr);
  --bottom-align:
    var(--align-top, 1fr)
    var(--align-center-y, 1fr)
    var(--align-bottom, 0fr);

  grid-template-columns: var(--left-align) auto var(--right-align);
  grid-template-rows: var(--top-align) auto var(--bottom-align);
  background: #ffc0cba3;
  transition: all 1s;
}

.popover-content {
  padding: 0.5em;
  transition: all 1s;
  grid-area: 2 / 2;
  place-self: var(--align, center center);
  background: #ff40ff;
  min-height: auto;
  min-width: auto;
}

fieldset {
  padding: 0.5em;
}

.code-placeholder {
  flex-grow: 1;
  anchor-name: --code-placeholder;
}

.popover::after {
  position: fixed;
  inset: calc(anchor(inside) + 0.5em);
  top: 1.5em;
  color: #000;
  content: 'inset-area: ' var(--code, 'center / center') ';';
  font-family: monospace;
  position-anchor: --code-placeholder;
}

.tether {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  z-index: -1; /* Not working well when intersecting */
  container-type: size;
  font-size: 0.75em;
}

@container (aspect-ratio < 1) {
  .tether > span {
    writing-mode: tb;
  }
}

body {
  display: grid;
  min-height: 100vh;
  grid-template-rows: max-content 1fr;
}

.controls {
  display: flex;
  gap: 0.5em;
  white-space: nowrap;
}

.root {
  anchor-name: var(--is);
  box-shadow: 0 -2px 0 #0003;
  overflow: hidden;
  resize: both;
}

.resizer {
  width: 15em;
  height: 10em;
  overflow: hidden;
  resize: both;
}

.outline {
  z-index: -2;
  position: fixed;
  outline: 1px solid #0004;
  pointer-events: none;
  position-anchor: var(--for);
}

.outline-top {
  top: anchor(top);
  inset-inline: anchor(var(--context) inside);
}
.outline-bottom {
  bottom: anchor(bottom);
  inset-inline: anchor(var(--context) inside);
}
.outline-left {
  left: anchor(left);
  inset-block: anchor(var(--context) inside);
}
.outline-right {
  right: anchor(right);
  inset-block: anchor(var(--context) inside);
}

dialog {
  z-index: 9;
  outline: 200vmax solid #1238;
  overflow: auto;
  max-height: 100vh;
  box-sizing: border-box;  
}

video {
  max-width: 100%;
  max-height: 100vh;
  width: 861px;
  height: 540px;
}

@supports (anchor-name: --foo) {
  dialog {
    display: none;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console