Introducing CSS Regions

Wdd Logo.
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

3 Essential Design Trends, November 2024

Touchable texture, distinct grids, and two-column designs are some of the most trending website design elements of…

20 Best New Websites, October 2024

Something we’re seeing more and more of is the ‘customizable’ site. Most often, this means a button to swap between…

Exciting New Tools for Designers, October 2024

We’ve got goodies for designers, developers, SEO-ers, content managers, and those of you who wear multiple hats. And,…

15 Best New Fonts, September 2024

Welcome to our roundup of the best new fonts we’ve found on the web in the previous four weeks. In this month’s edition…

3 Essential Design Trends, October 2024

This article is brought to you by Constantino, a renowned company offering premium and affordable website design You…

A Beginner’s Guide to Using BlueSky for Business Success

In today’s fast-paced digital world, businesses are always on the lookout for new ways to connect with their audience.…

The Importance of Title Tags: Tips and Tricks to Optimize for SEO

When it comes to on-page SEO, there’s one element that plays a pivotal role in both search engine rankings and user…

20 Best New Websites, September 2024

We have a mixed bag for you with both minimalist and maximalist designs, and single pagers alongside much bigger, but…

Exciting New Tools for Designers, September 2024

This time around we are aiming to simplify life, with some light and fast analytics, an all-in-one productivity…

3 Essential Design Trends, September 2024

September's web design trends have a fun, fall feeling ... and we love it. See what's trending in website design this…

Crafting Personalized Experiences with AI

Picture this: You open Netflix, and it’s like the platform just knows what you’re in the mood for. Or maybe you’re…

15 Best New Fonts, August 2024

Welcome to August’s roundup of the best fonts we’ve found over the last few weeks. 2024’s trend for flowing curves and…