CSS Exclusions and Grid Layout

Rachel Andrew
Mar 16, 2016 · 3 min read

I’ve seen a little bit of interest around Exclusions lately, and so am reposting the piece that was originally posted on my blog in 2016. I would love to see Exclusions have more interest. Take a look!

There is a tiny little specification that originally started life linked to the Shapes specification, the original Exclusions and Shapes draft defined both shape-inside and shape-outside along with properties wrap-flow and wrap-through. These properties were to create Exclusions.

The Exclusions and Shapes specification was split. The shape-outside property went into Level 1 of CSS Shapes and is now implemented in some browsers. The shape-inside property, was moved to Level 2 of that module. The properties that create exclusions were moved to their own specification. At the current time the only browsers with support for exclusions are Internet Explorer 10, 11 and Edge.

What is an exclusion?

In CSS we can create text wrapped around elements by using floats. If we float an element left or right the following content will wrap around it. However there is no way to float an item right in the middle of some content with text flowing around it.

This is what exclusions do.

The specification doesn’t create a new method of positioning elements, so needs combining with a positioning method. It becomes especially interesting when combined with the upcoming CSS Grid Specification.

In order to take a look I need to use Edge, and therefore the “old” prefixed version of CSS Grid which is implemented in that browser. I’ve added the new syntax as well. If you have IE 10, 11 or Edge then you can take a look at the CodePen examples I have linked.

In the CodePen you can see that I have created a Grid on wrapper which has two child elements, the content in a div with a class of inner and an image which has a class of exclusion. The content I have stretched to cover the entire grid, but the image I have positioned on the grid, it will then sit on top of the content.

By setting wrap-flow: both on the image however it becomes an exclusion. The text knows it is there and flows round both sides of the item.

View the CodePen for demo 1

You can get pretty creative with this.

View the CodePen for demo 2

Here is an example of using media queries to change the display on viewport width. On narrow windows the exclusions insert the images into the content at full width, at wider windows we have content wrapped on the internal side and the image appearing pulled out of the content.

All of the content is in one article, not broken up by the images in the source.

Here is the CodePen for the responsive example

A video of the responsive grid and exclusions demo

Grid and Exclusions make sense together

With CSS Grid we can use auto placement to position child elements each in a cell of the grid, enabling a display like this example.

What the addition of exclusions would give us is the ability to define a grid and place items on it — be that images, content, perhaps advertising elements that we don’t want to actually break up an article to insert. Then flow content naturally around that.

No signals

Currently there appears to be no activity around Exclusions. You can see the Chrome Platform Status details here which also lists what other browser vendors and the development community are thinking about this feature. I think it is something we will find useful once Grid ships. I’d love to see other use cases and demos!

Originally published at rachelandrew.co.uk on March 16, 2016.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store