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.
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;
column-rule-color: rebeccapurple;
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
/* Keywords */
rule-inset-cap: overlap-join;
/* A <length-percentage> value */
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 from the following list:
overlap-join-
Resolves to
0. <length-percentage>-
Specifies the size of the inset. Percentage values resolve to
0for caps at the container's edge. For interior gaps, percentages are relative to the height of the adjacentrow-gapfor column segment caps, or the width of the adjacentcolumn-gapfor row segment caps.
Description
The rule-inset-cap shorthand property sets the column-rule-inset-cap and row-rule-inset-cap properties, insetting cap segment endpoints by the specified values. Positive values reduce the segment size, while negative values increase it.
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 shows how to set rule-inset-cap to inset the endpoints of cap segments on flex containers.
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 flex-wrap and flex-line-count. We define a light blue rule to paint in both row and column gaps, then override the column-rule-color, setting darker blue vertical gap decorations. Finally, we set the rule-inset-cap to 16px.
.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. We've hidden the other CSS styles, and the code that make the form interactive, for brevity.
.column {
flex-direction: column;
}
Result
Change the size of the inset.
Inner cap segments
This example shows how to set 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.
<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 inset size.
<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 row rule color with the row-rule-color property. We set the rule-break property to break the rules at each intersection, making each rule segment distinct. We explicitly set rule-visibility-items to the default value of normal. We then use the rule-inset-cap property to inset all the cap segment endpoints by 16px.
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, thereby creating interior cap segments. Then change the inset value.
Specifications
| Specification |
|---|
| CSS Gaps Module Level 1> # propdef-rule-inset-cap> |
Browser compatibility
See also
column-rule-inset-capshorthandrow-rule-inset-capshorthandcolumn-rule-insetshorthandrow-rule-insetshorthandrule-inset-startshorthandrule-insetshorthandrule-breakshorthand\rule-overlaprule-visibility-itemsruleshorthand- CSS gaps module