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

              
                <header class="intro">
  <label>
    <b>Font</b>: 
    <select id="tbFont">
      <option selected value="var(--font-system-ui)">System UI</option>
      <option value="var(--font-old-style)">Old Style</option>
      <option value="var(--font-neo-grotesque)">Neo Grotesque</option>
      <option value="var(--font-rounded-sans)">Rounded Sans</option>
      <option value="var(--font-antique)">Antique</option>
      <option value="var(--font-handwritten)">Handwritten</option>
      <option value="var(--font-transitional)">Transitional</option>
      <option value="var(--font-industrial)">Industrial</option>
      <option value="var(--font-slab-serif)">Slab Serif</option>
      <option value="Fantasy">Fantasy</option>
      <option value="var(--font-humanist)">Humanist</option>
      <option value="var(--font-geometric-humanist)">Geometric Humanist</option>
      <option value="var(--font-classical-humanist)">Classical Humanist</option>
      <option value="var(--font-monospace-slab-serif)">Monospace Slab Serif</option>
      <option value="var(--font-monospace-code)">Monospace Code</option>
    </select>
  </label>

  <output><span class="property">text-box</span>: <span id="tbTrim">trim-both</span> <span id="tbEdgeOver">cap</span> <span id="tbEdgeUnder">alphabetic</span>;</output>
</header>

<section>
  <label style="text-decoration: wavy var(--edge, underline overline) var(--color-edge)"> 
    <b>Edge</b>:
    <select id="tbTrimOptions"> 
      <option>none</option>
      <hr>
      <option>trim-start</option>
      <option>trim-end</option>
      <option selected>trim-both</option>
    </select>
  </label>

  <label>
    Trim <b style="text-decoration: solid overline var(--color-over)">over</b> at: 
    <select id="tbEdgeOverOptions">
      <option selected>cap</option>
      <option>ex</option>
      <option>text</option>
      <hr>
      <optgroup label="CJK" disabled>
        <option>ideographic</option>
        <option>ideographic-ink</option>
      </optgroup>
      <hr>
      <option>leading (initial)</option>
    </select>
  </label>

  <label>
    Trim <b style="text-decoration: solid underline var(--color-under)">under</b> at: 
    <select id="tbEdgeUnderOptions">
      <option selected>alphabetic</option>
      <option>text</option>
      <hr>
      <optgroup label="CJK" disabled>
        <option>ideographic</option>
        <option>ideographic-ink</option>
      </optgroup>
    </select>
  </label>
</section>

<div class="stack">
  <h1 contenteditable spellcheck="false">Hx Qj</h1>
  <h1 contenteditable spellcheck="false">角</h1>
</div>

<p contenteditable spellcheck="false">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Earum, omnis fuga suscipit enim sequi, harum consequatur, magni iste eum deleniti sit quae! Reprehenderit incidunt vero unde voluptates sapiente laborum repudiandae?</p>

<div class="stack">
  <h2 contenteditable spellcheck="false">abcdefg<br>hijklmnop<br>qrstuv<br>wxyz</h2>
  <h2 contenteditable spellcheck="false">XOXO<br>OXOX</h2>
</div>

<div class="edge-tip" id="tipOver">cap</div>
<div class="edge-tip" id="tipUnder">alphabetic</div>
              
            
!

CSS

              
                @import "https://unpkg.com/open-props/fonts.min.css";

h1, h2, p {
  text-box: 
    var(--tbTrim, trim-both) 
    var(--tbEdgeOver, cap) 
    var(--tbEdgeUnder, alphabetic)
  ;
  font-family: var(--tbFont, var(--system-ui, sans-serif));
}







@layer support {
  * {
    box-sizing: border-box;
    margin: 0;
  }

  html {
    block-size: 100%;
    color-scheme: light;
    
    --color-edge: #50FA7B;
    --color-over: #BD93F9;
    --color-under: #FF79C6;
  }

  body {
    min-block-size: 100%;
    font-family: system-ui, sans-serif;

    display: grid;
    place-content: center;
    place-items: center;
    
    gap: 10vmin;
    padding: 10vmin;
  }
  
  output {
    font-size: 1rem;
    font-family: monospace;
    background: #222;
    color: #eee;
    padding: 1ch 1.5ch;
    border-radius: 1ch;
    white-space: nowrap;
    
    > #tbTrim       { color: var(--color-edge) }
    > #tbEdgeOver   { color: var(--color-over) }
    > #tbEdgeUnder  { color: var(--color-under) }
    
    > [id] { font-weight: bold }
  }
  
  select {
    field-sizing: content;
  }
  
  h1 {
    font-size: clamp(3rem, 20vw, 8rem);
  }
  
  h2 {
    font-size: clamp(2rem, 10vw, 6rem);
    max-inline-size: 12ch;
    line-height: 1.1cap;
  }
  
  p {
    max-inline-size: 40ch;
    text-wrap: pretty;
  }
  
  h1, h2, p {
    text-wrap: stable;
    color: #000b;
    border-image: 
      linear-gradient(
        to bottom in oklch, 
        var(--color-over) 2px, 
        #0000 0, 
        #0000 calc(100% - 2px), 
        var(--color-under) 0
      ) 
      fill 0//0 100vw
    ;
  }
  
  section {
    font-size: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    white-space: nowrap;
    place-content: center;
    gap: 3ch 2ch;
    margin-block-end: 5vmin;
    
    @media (width <= 768px) {
      flex-direction: column;
      place-items: center;
    }
    
    label {
      text-box: trim-both cap alphabetic;
    }
  }
  
  select {
    background: none;
    border: none;
    font: inherit;
    font-weight: 200;
  }
  
  .intro {
    display: grid;
    place-items: center;
    gap: 1ch;
  }
  
  .stack {
    display: grid;
    place-items: center;
    gap: 10vw;
  }
  
  .edge-tip {
    position-anchor: --edge-tip-target;
    position-area: var(--_pos) left;
    position: fixed;
    left: -100vw;
    padding-inline-end: calc(10px + .5ch);
    
    &::after {
      display: block;
      content: "";
      
      position-anchor: --edge-tip-target;
      position: fixed;
    }
    
    &#tipOver {
      color: rebeccapurple;
      --_pos: top;
      
      &::after {
        left: calc(anchor(left) - 10px);
        bottom: anchor(top);
        right: anchor(left);
        top: calc(anchor(top) - 10px);
        border-top: 1px dashed var(--color-over);
        border-right: 1px dashed var(--color-over);
        border-radius: 0 3px 0 0;
      }
    }
    
    &#tipUnder {
      padding-block-start: .5ex;
      color: deeppink;
      --_pos: bottom;
      
      &::after {
        left: calc(anchor(left) - 10px);
        bottom: calc(anchor(bottom) - 10px - .5ex);
        right: anchor(left);
        top: anchor(bottom);
        border-bottom: 1px dashed var(--color-under);
        border-right: 1px dashed var(--color-under);
        border-radius: 0 0 3px 0;
      }
    }
  }
  
  :is(h1,h2,p):is(:hover,:focus-visible) {
    anchor-name: --edge-tip-target;
  }
  
  @media (prefers-reduced-motion: no-preference) {
    :focus {
      transition: outline-offset .25s ease;
    }
    :focus:not(:active) {
      outline-offset: 3px;
    }
  }
}
              
            
!

JS

              
                tbTrimOptions.oninput = () => {
  let {value} = tbTrimOptions
  document.body.style.setProperty('--tbTrim', value)
  tbTrim.innerText = value
  
  if (value == 'trim-start')
    document.body.style.setProperty('--edge', 'overline')
  else if (value == 'trim-end')
    document.body.style.setProperty('--edge', 'underline')
  else if (value == 'none')
    document.body.style.setProperty('--edge', '0')
  else
    document.body.style.setProperty('--edge', 'overline underline')
}

tbEdgeOverOptions.oninput = () => {
  let {value} = tbEdgeOverOptions
  document.body.style.setProperty('--tbEdgeOver', value)
  tbEdgeOver.innerText = value
  tipOver.innerText = value
}

tbEdgeUnderOptions.oninput = () => {
  let {value} = tbEdgeUnderOptions
  document.body.style.setProperty('--tbEdgeUnder', value)
  tbEdgeUnder.innerText = value
  tipUnder.innerText = value
}

tbFont.oninput = () => {
  let {value} = tbFont
  document.body.style.setProperty('--tbFont', value)
}

// check for CJK support
if (CSS.supports('text-box: ideographic')) {
  // enable select box option groups if true
  tbEdgeOverOptions.querySelector('[label="CJK"]').disabled = false
  tbEdgeUnderOptions.querySelector('[label="CJK"]').disabled = false
}
              
            
!
999px

Console