4 years in the past, I wrote an article titled Minding the “hole”, the place I talked concerning the CSS hole
property, the place it utilized, and the way it labored with varied CSS layouts.
On the time, I described how straightforward it was to evenly area gadgets out in a flex, grid, or multi-column format, through the use of the hole
property. However, I additionally mentioned that styling the hole areas was a lot tougher, and I shared a workaround.
Nonetheless, workarounds like utilizing further HTML components, pseudo-elements, or borders to attract separator strains have a tendency to come back with drawbacks, particularly those who influence your format dimension, intervene with assistive applied sciences, or pollute your markup with style-only components.
Right this moment, I’m writing once more about format gaps, however this time, to inform you all a couple of new and thrilling CSS characteristic that’s going to vary all of it. What you beforehand had to make use of workarounds for, you’ll quickly have the ability to do with only a few easy CSS properties that make it straightforward, but additionally versatile, to show styled separators between your format gadgets.
There’s already a specification draft for the characteristic you possibly can peruse. On the time I’m penning this, it’s obtainable in Chrome and Edge 139 behind a flag. However I consider it gained’t be lengthy earlier than we flip that flag on. I consider different browsers are additionally very receptive and engaged.
Displaying ornamental strains between gadgets of a format could make an enormous distinction. When used effectively, these strains can carry extra construction to your format, and provides your customers extra of a way of how the totally different areas of a web page are organized.
Introducing CSS hole decorations
Should you’ve ever used a multi-column format, reminiscent of through the use of the column-width
property, then you definitely would possibly already be aware of hole decorations. You’ll be able to draw vertical strains between the columns of a multi-column format through the use of the column-rule
property:
article {
column-width: 20rem;
column-rule: 1px strong black;
}

The CSS hole decorations characteristic builds on this to offer a extra complete system that makes it straightforward so that you can draw separator strains in different format sorts.
For instance, the draft specification says that the column-rule
property additionally works in flexbox and grid layouts:
.my-grid-container {
show: grid;
hole: 2px;
column-rule: 2px strong pink;
}

No want for further components or borders! The important thing profit right here is that the ornament occurs in CSS solely, the place it belongs, with no impacts to your semantic markup.
The CSS hole decorations characteristic additionally introduces a brand new row-rule
property for drawing strains between rows:
.my-flex-container {
show: flex;
hole: 10px;
row-rule: 10px dotted limegreen;
column-rule: 5px dashed coral;
}

However that’s not all, as a result of the above syntax additionally means that you can outline a number of, comma-separated, line model values, and use the identical repeat()
perform that CSS grid already makes use of for row and column templates. This makes it doable to outline totally different types of line decorations in a single format, and adapt to an unknown variety of gaps:
.my-container {
show: grid;
hole: 2px;
row-rule:
repeat(2, 1px dashed crimson),
2px strong black,
repeat(auto, 1px dotted inexperienced);
}
Lastly, the CSS hole decorations characteristic comes with extra CSS properties reminiscent of row-rule-break
, column-rule-break
, row-rule-outset
, column-rule-outset
, and gap-rule-paint-order
, which make it doable to exactly customise the best way the separators are drawn, whether or not they overlap, or the place they begin and finish.
And naturally, all of this works throughout grid, flexbox, multi-column, and shortly, masonry!
Browser assist
At present, the CSS hole decorations characteristic is simply obtainable in Chromium-based browsers.
The characteristic continues to be early within the making, and there’s time for you all to strive it and to offer suggestions that might assist make the characteristic higher and extra tailored to your wants.
If you wish to strive the characteristic as we speak, be sure to make use of Edge or Chrome, beginning with model 139 (or one other Chromium-based browser that matches these variations), and allow the flag by following these steps:
- In Chrome or Edge, go to
about://flags
. - Within the search area, seek for Allow Experimental Net Platform Options.
- Allow the flag.
- Restart the browser.
To place this all into observe, let’s stroll by way of an instance collectively that makes use of the brand new CSS hole decorations characteristic. I even have a remaining instance you possibly can demo.
Utilizing CSS hole decorations
Let’s construct a easy net web page to discover ways to use the characteristic. Here’s what we’ll be constructing:
The above format comprises a header part with a title, a navigation menu with a number of hyperlinks, a essential part with a collection of brief paragraphs of textual content and pictures, and a footer.
We’ll use the next markup:
...
...
...
...
...
We’ll begin by making the factor be a grid container. This manner, we will area out the
,
, and
components aside in a single go through the use of the hole
property:
physique {
show: grid;
hole: 4rem;
margin: 2rem;
}
Let’s now use the CSS hole decorations characteristic to show horizontal separator strains inside the gaps we simply outlined:
physique {
show: grid;
hole: 4rem;
margin: 2rem;
row-rule: 1rem strong #efefef;
}
This provides us the next end result:
We will do a bit higher by making the primary horizontal line look totally different than the opposite two strains, and simplify the row-rule
worth through the use of the repeat()
syntax:
physique {
show: grid;
hole: 4rem;
margin: 2rem;
row-rule:
1rem strong #efefef,
repeat(2, 2px strong #efefef);
}
With this new row-rule
property worth, we’re telling the browser to attract the primary horizontal separator as a 1rem
thick line, and the following two separators as 2px
thick strains, which provides the next end result:
Now, let’s flip our consideration to the navigation factor and its record of hyperlinks. We’ll use flexbox to show the hyperlinks in a single row, the place every hyperlink is separated from the opposite hyperlinks by a niche and a vertical line:
nav ul {
show: flex;
flex-wrap: wrap;
hole: 2rem;
column-rule: 2px dashed #666;
}
Very equally to how we used the row-rule
property earlier than, we’re now utilizing the column-rule
property to show a dashed 2px
thick separator between the hyperlinks.
Our instance net web page now seems like this:

The very last thing we have to change is the factor and its paragraphs and footage. We’ll use flexbox once more and show the varied youngsters in a wrapping row of various width gadgets:
essential {
show: flex;
flex-wrap: wrap;
hole: 4rem;
}
essential > * {
flex: 1 1 200px;
}
essential article:has(p) {
flex-basis: 400px;
}
Within the above code snippet, we’re setting the factor to be a wrapping flex container with a
4rem
hole between gadgets and flex strains. We’re additionally making the gadgets have a flex foundation dimension of 200px
for footage and 400px
for textual content, and permitting them to develop and shrink as wanted. This provides us the next end result:
Let’s use CSS hole decorations to carry just a little extra construction to our format by drawing 2px
thick separator strains between the rows and columns of the format:
essential {
show: flex;
flex-wrap: wrap;
hole: 4rem;
row-rule: 2px strong #999;
column-rule: 2px strong #999;
}
This provides us the next end result, which may be very near our anticipated design:

The final element we wish to change is said to the vertical strains. We don’t need them to span throughout your entire peak of the flex strains however as an alternative begin and cease the place the content material begins and stops.
With CSS hole decorations, we will simply obtain this through the use of the column-rule-outset
property to fine-tune precisely the place the decorations begin and finish, relative to the hole space:
essential {
show: flex;
flex-wrap: wrap;
hole: 4rem;
row-rule: 2px strong #999;
column-rule: 2px strong #999;
column-rule-outset: 0;
}
The column-rule-outset
property above makes the vertical column separators span the peak of every row, excluding the hole space, which is what we wish:

And with that, we’re completed with our instance. Try the reside instance, and supply code.
Study extra
There’s extra to the characteristic and I discussed a pair extra CSS properties earlier
gap-rule-paint-order
, which helps you to management which of the decorations, rows or columns, seem above the opposite ones.row-rule-break
/column-rule-break
, which units the habits of the ornament strains at intersections. Specifically, whether or not they’re made from a number of segments, which begin and finish at intersections, or single, steady strains.
As a result of the characteristic is new, there isn’t MDN documentation about it but. So to study extra, try:
The Edge group has additionally created an interactive playground the place you should utilize visible controls to configure hole decorations.
And, in fact, the rationale that is all applied behind a flag is to elicit suggestions from builders such as you! In case you have any suggestions, questions, or bugs about this characteristic, I positively encourage you to open a brand new ticket on the Chromium situation tracker.