rule-inset-cap CSS property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Want more browser support for this feature? Tell us why.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The rule-inset-cap CSS shorthand property can be used to offset the start and end of column and row rule segment cap endpoints to the same value.

Try it

rule-inset-cap: -20px;
rule-inset-cap: 0;
rule-inset-cap: 1em;
rule-inset-cap: 100%;
rule-inset-cap: overlap-join;
<section id="default-example">
  <div id="example-element">
    <i>A</i>
    <i>B</i>
    <i>C</i>
    <i>D</i>
    <i>E</i>
    <i>F</i>
    <i>G</i>
    <i>H</i>
    <i>I</i>
    <i>J</i>
    <i>K</i>
    <i>L</i>
    <i>M</i>
    <i>N</i>
    <i>O</i>
    <i>P</i>
    <i>Q</i>

    <i id="y">Y</i>
    <i id="z">Z</i>
    <i id="bang">!</i>
  </div>
</section>
#example-element {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  rule: solid thick magenta;
  gap: 1em;
  rule-overlap: column-over-row;
  rule-visibility-items: between;
  border: 1px solid rebeccapurple;
  overflow: visible;
  margin: 1em;
}
#example-element i {
  padding: 8px;
  border: 1px dashed;
}
#y {
  grid-column: 4 / 5;
  grid-row: 4 / 5;
}
#z {
  grid-column: 5 / 6;
  grid-row: 4 / 5;
}
#bang {
  grid-column: 6 / 7;
  grid-row: 4 / 5;
}

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

css
/* Keywords */
rule-inset-cap: overlap-join;

/* <length-percentage> values */
rule-inset-cap: 0;
rule-inset-cap: 1em;
rule-inset-cap: -5px;
rule-inset-cap: -25%;

/* Global values */
rule-inset-cap: inherit;
rule-inset-cap: initial;
rule-inset-cap: revert;
rule-inset-cap: revert-layer;
rule-inset-cap: unset;

Values

This property is specified as a single value from the following list:

overlap-join

Resolves to 0.

<length-percentage>

Specifies the size of the inset. Percentage values are relative to the cap endpoint, which is either row-gap or 0 for column segments, and either column-gap or 0 for row segments.

Description

The rule-inset-cap shorthand property sets the column-rule-inset-cap and row-rule-inset-cap properties to the same value, insetting cap segment endpoints by the specified value. Positive values reduce the size of the cap segments. Negative values extend them.

The rule-inset-cap property, along with the rule-inset-junction property, can be set using the rule-inset shorthand.

Formal definition

Value not found in DB!

Formal syntax

rule-inset-cap = 
<'column-rule-inset-cap'>

<column-rule-inset-cap> =
<inset-value> <inset-value>?

<inset-value> =
<length-percentage> |
overlap-join

<length-percentage> =
<length> |
<percentage>

Examples

Basic usage

This example demonstrates setting rule-inset-cap to inset the endpoints of cap segments on flex containers.

HTML

html
<h1>Insetting cap endpoints</h1>
<article>
  <section>
    <h2>flex-direction: row</h2>
    <div class="flexbox">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
  </section>
  <section>
    <h2>flex-direction: column</h2>
    <div class="flexbox column">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
  </section>
</article>

CSS

We use the display property to turn the .flexbox elements into flex containers. We balance the items into three flex lines using with flex-wrap and flex-line-count. We define a light blue rule to be painted in both row and column gaps, then overwrite the column-rule-color, setting darker blue vertical gap decorations. Finally, we set the rule-inset-cap to 16px.

css
.flexbox {
  display: flex;
  flex-wrap: balance;
  flex-line-count: 3;
  gap: 20px;
  rule: 5px solid lightblue;
  column-rule-color: blue;

  rule-inset-cap: 16px;
}

We also set the flex-direction on the .column container to make its items flow in columns rather than rows.

css
.column {
  flex-direction: column;
}

The rest of the CSS is hidden for brevity.

Result

Change the size of the inset.

Inner cap segments

This example demonstrates setting rule-inset-cap to inset the endpoints of cap segments on a grid container, and how the rule-visibility-items property can turn inner endpoints into cap segment endpoints.

HTML

We include an unordered list (<ul>) as our container for several list items (<li>).

We also include a <select> element with an <option> for each rule-visibility-items keyword, and an <input> of type range.

html
<ul id="ul">
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
  <li>13</li>
  <li>14</li>
  <li>15</li>
  <li>16</li>
  <li>17</li>
</ul>

<p>
  <label
    ><code>rule-visibility-items</code> value <code>
    <select id="visibility">
      <option>all</option>
      <option>between</option>
      <option>around</option>
      <option selected>normal</option>
  </select>
  </label>
</p>

<p>
  <label
    >Change the size of the inset.
    <input type="range" min="-40" max="16" value="0" id="inset" data-unit="px"
  /></label>
  <output id="o"></output>
</p>

CSS

We create a grid container by setting the display to grid, creating 6 columns with grid-template-columns, and adding a 20px gap. We use the rule property to define our rules, overriding the color of for our row rules with the row-rule-color property. We set the rule-break property to make the rules break at each intersection, to make each rule segment distinct. We explicitly set the display to the default value of normal. We then use the rule-inset-cap property to inset all the cap segment endpoints by 16px.

css
ul {
  display: grid;
  grid-template-columns: repeat(6, auto);
  gap: 20px;
  rule: 10px solid olive;
  row-rule-color: palegoldenrod;
  rule-break: intersection;
  rule-visibility-items: normal;

  rule-inset-cap: 16px;
}

We've hidden the other CSS styles, and the code that make the form interactive, for brevity.

Result

Select between from the dropdown to only paint rule segments when both adjacent grid areas contain a grid item, then change the value of the inset.

Specifications

Specification
CSS Gaps Module Level 1
# propdef-rule-inset-cap

Browser compatibility

See also