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

              
                <p>There is a bug in Chrome 128 where the mask-image is not rendered correctly.</p>

<div class="tools">
  <label for="radiusRange">Inner Radius: </label>
  <input type="range" id="radiusRange" name="radius" min="0" max="150" value="10">
  <span id="radiusValue">10</span>px
</div>

<div class="demo">
  <div class="box">
    box
  </div>

  <div class="box box2">
    box2
  </div>
</div>

<svg width="0" height="0">
  <defs>
    <!-- 圆角矩形 -->
    <mask id="mask-inner" maskUnits="objectBoundingBox">
      <rect fill="#92C2FF" x="var(--border-width)" y="var(--border-top-width)" width="var(--size)" height="var(--size)" rx="var(--inner-radius)"></rect>
    </mask>
    <!-- 矩形 -->
    <mask id="mask-outer" maskContentUnits="objectBoundingBox">
      <rect fill="pink" x="0" y="0" width="1" height="1"></rect>
    </mask>
  </defs>
</svg>
              
            
!

CSS

              
                :root {
  --bd-color: #7f48b1;
  --lg: linear-gradient(145deg, #80a3fa, #f3198a);
  --inner-radius: 20px;
  --border-width: 10px;
  --border-top-width: 40px;
  --size: 230px;
  --svg-width: calc(var(--size) + var(--border-width) * 2);
  --svg-height: calc(
    var(--size) + var(--border-width) + var(--border-top-width)
  );
}

p {
  text-align: center;
}

.demo {
  padding: 3em 0;
  background: repeating-linear-gradient(45deg, #ccc 0 10px, #eee 0 20px) fixed;
}

.tools {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2em;
}

.demo {
  display: flex;
  justify-content: center;
  gap: 2em;
}

.box {
  display: inline-flex;
  justify-content: center;
  border: var(--border-width) solid var(--bd-color);
  border-radius: var(--border-width);
  width: var(--size);
  min-height: var(--size);
  border-top-width: var(--border-top-width);
}

.box2 {
  position: relative;

  // background-clip: border-area, Safari TP 202+
  // background: var(--lg) border-area border-box;
}

.box2:after {
  content: "";
  border-radius: 10px;
  position: absolute;
  top: calc(var(--border-top-width) * -1);
  left: calc(var(--border-width) * -1);
  right: calc(var(--border-width) * -1);
  bottom: calc(var(--border-width) * -1);
  background: #f549ad75;
  background-image: var(--lg);

  mask-image: url(#mask-inner), url(#mask-outer);
  mask-mode: alpha;
  mask-composite: exclude;
}

              
            
!

JS

              
                 // 获取 range 输入和显示当前值的元素
    const rangeInput = document.getElementById('radiusRange');
    const radiusValueDisplay = document.getElementById('radiusValue');

    // 添加 input 事件监听器
    rangeInput.addEventListener('input', function() {
      // 获取 range 输入的值
      const radiusValue = rangeInput.value + 'px';
      // 设置 CSS 变量 --radius 的值
      document.documentElement.style.setProperty('--inner-radius', radiusValue);
      // 更新显示当前值的元素
      radiusValueDisplay.textContent = rangeInput.value;
    });
              
            
!
999px

Console