Introducing CSS Regions

Default avatar.
September 30, 2013
Introducing CSS Regions.

thumbnailBuilding complex, flexible layouts has never been easy, but CSS3 has certainly taken away a lot of the headaches.

CSS3 features like Flexbox and Columns have made some complex layouts a real possibility and now they’re being joined by one of the newest additions to the web designer’s toolbox: CSS Regions.

CSS Regions allow you to flow content into a series of containers on a single page. It’s the equivalent of linking text boxes in an application like InDesign. It makes possible some layouts that were previously only possible by blurring the line between data and styles.

Browser support

As always, browser support is far from perfect.

CSS Regions is still a draft, which means it’s experimental. Initially the only browser to actually support it was Internet Explorer 10 (no, I’m not kidding); although IE10 does use an iframe as the content source.

Safari claims to offer support with a prefix.

In Chrome you can test the feature by opening your browser, typing about:flags’ and activating enable-experimental-webkit-features’, then restarting your browser.

Happily there is also a JavaScript polyfill created by Adobe that brings the functionality of CSS Regions to browsers that currently don’t support it, you can find this on github.

Using CSS Regions

Since the purpose of CSS Regions is to allow our text to flow across different containers, the first thing you need is some text:

<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc cursus imperdiet purus ac eleifend. Vivamus posuere pellentesque nibh vel laoreet. Donec et sem odio. Donec sit amet lorem hendrerit, faucibus libero et, mattis lacus. Suspendisse dapibus rutrum felis quis interdum. Integer tincidunt, orci at condimentum placerat, est nulla sollicitudin velit, vitae gravida nisi odio ac ligula. Sed hendrerit ac massa vel ultricies. Vestibulum commodo, orci et tincidunt laoreet, enim tellus aliquet orci, quis dapibus sapien tellus eu felis. Etiam non arcu at eros luctus consectetur vitae eget nunc. In felis ipsum, vehicula ac mauris vel, porttitor gravida neque.
Quisque orci turpis, aliquam vel tortor convallis, ullamcorper molestie nisl. Sed aliquet dignissim lorem non fringilla. In hac habitasse platea dictumst. In hac habitasse platea dictumst. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue erat ac hendrerit ullamcorper. Morbi facilisis urna nunc, eget pretium lectus congue vitae.
</div>

And then some containers:

<div class="containers"></div>
<div class="containers"></div>
<div class="containers"></div>

Now we have the basic content set up, we can link the containers using flow-into and flow-from, you’ll notice in the example I’ve added the -webkit- prefix.

.text {
 -webkit-flow-into: text-flow;
 padding: 0;
 margin: 0;
 color: #F2F2F2;
 font-family: helvetica, arial;
 font-size: 16px;
 line-height: 22px;
}
 
.containers{
 -webkit-flow-from: text-flow;
 background: #333333;
 padding: 5px;
 margin-top: 100px;
 width: 200px;
 height: 300px;
 float: left;
 margin-right: 20px;
}

If you check this in a browser you’ll see that the text will just flow from one box to another. If you now position those containers, the text will continue to flow properly.

Understanding flow-into

-webkit-flow-into: text-flow;

This property accepts an identifier as the value. When you pass a value to this property it becomes part of a named flow and it will stop rendering as part of the page flow. You can cancel that by setting the property to none.

The name of the flow you use is arbitrary, just make sure you’re consistent. We can also have multiple elements with the same named flow as in our example above.

This isn’t limited to text, we can also flow images, lists, and many other kinds of HTML content.

Understanding flow-from

-webkit-flow-from: text-flow;

We use this property to specify which element(s) should receive the specified flow.

The value is the name of the flow that we specified for the flow-into property.

Bear in mind that any content styles that you apply to the original text will be maintained across the flow. So if you color the text blue, it will remain blue across all containers.

Final thoughts

To see an example of CSS Regions in action, take a look at this pen I created.

The browser support for CSS Regions is currently weak, and there’s a long way to go before we can rely on it on a daily basis. But, the flexibility that it offers is fantastic, and once full support is in place I think CSS Regions will be the go-to technique for years to come.

Are you excited by CSS Regions? How soon do you think we’ll be able to use them? Let us know in the comments.

Featured image/​thumbnail, waterfall image via cuatrok77.

WDD Staff

WDD staff are proud to be able to bring you this daily blog about web design and development. If there’s something you think we should be talking about let us know @DesignerDepot.

Read Next

15 Best New Fonts, May 2023

The choices you make when selecting a typeface have more impact on your design than almost any other decision, so it’s …

10+ Best Tools & Resources for Web Designers and Agencies (2023 updated)

Having the ability to envision a tastefully designed website (i.e., the role creativity plays) is important. But being …

20 Best New Websites, May 2023

This month, there are tons of great new agency websites to get excited about. 3D animated prisms are a popular theme, a…

How to Find the Right White Label Website Builder for Your Agency

Web design agencies face a lot of obstacles in closing the deal with new clients. One of the most common ones is the ar…

Exciting New Tools For Designers, May 2023

There are hundreds of new tools for designers and developers released each month. We sift through them all to bring you…

3 Essential Design Trends, May 2023

All three of the website design trends here mimic something bigger going on in the tech space, from a desire to have mo…

10 Best AI Tools for Web Designers (2023)

It’s time to stop worrying if AI is going to take your job and instead start using AI to expand the services you can of…

10 Best Marketing Agency Websites (Examples, Inspo, and Templates!)

Marketers are skilled in developing strategies, producing visual assets, writing text with high impact, and optimizing …

15 Best New Fonts, April 2023

Fonts are a designer’s best friend. They add personality to our designs and enable fine typography to elevate the quali…

20 Best New Websites, April 2023

In April’s edition, there’s a whole heap of large-scale, and even full-screen, video. Drone footage is back with a veng…

Exciting New Tools For Designers, April 2023

The AI revolution is having a huge impact on the types of products that are hitting the market, with almost every app b…

3 Essential Design Trends, March 2023

One thing that we often think about design trends is that they are probably good to make a list. That’s not always true…