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

10+ Best Resources & Tools for Web Designers (2024 update)

Is searching for the best web design tools to suit your needs akin to having a recurring bad dream? Does each…

3 Essential Design Trends, April 2024

Ready to jump into some amazing new design ideas for Spring? Our roundup has everything from UX to color trends…

How to Plan Your First Successful Website

Planning a new website can be exciting and — if you’re anything like me — a little daunting. Whether you’re an…

15 Best New Fonts, March 2024

Welcome to March’s edition of our roundup of the best new fonts for designers. This month’s compilation includes…

LimeWire Developer APIs Herald a New Era of AI Integration

Generative AI is a fascinating technology. Far from the design killer some people feared, it is an empowering and…

20 Best New Websites, March 2024

Welcome to our pick of sites for March. This month’s collection tends towards the simple and clean, which goes to show…

Exciting New Tools for Designers, March 2024

The fast-paced world of design never stops turning, and staying ahead of the curve is essential for creatives. As…

Web Tech Trends to Watch in 2024 and Beyond

It hardly seems possible given the radical transformations we’ve seen over the last few decades, but the web design…

6 Best AI Productivity Apps in 2024

There’s no escaping it: if you want to be successful, you need to be productive. The more you work, the more you…

3 Essential Design Trends, February 2024

From atypical typefaces to neutral colors to unusual user patterns, there are plenty of new website design trends to…

Surviving the Leap from College to Real-World Design

So, you’ve finished college and are ready to showcase your design skills to the world. This is a pivotal moment that…

20 Mind-Bending Illusions That Will Make You Question Reality

Mind-bending videos. Divisive Images. Eye-straining visuals. This list of optical illusions has it all. Join us as we…