{"id":262731,"date":"2017-11-18T14:55:49","date_gmt":"2017-11-18T21:55:49","guid":{"rendered":"http:\/\/css-tricks.com\/?p=262731"},"modified":"2017-11-18T14:55:49","modified_gmt":"2017-11-18T21:55:49","slug":"simple-patterns-for-separation","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/simple-patterns-for-separation\/","title":{"rendered":"Simple Patterns for Separation (Better Than Color Alone)"},"content":{"rendered":"

Color is pretty good for separating things. That’s what your basic pie chart is, isn’t it? You tell the slices apart by color. With enough color contrast, you might be OK, but you might be even better off (particularly where accessibility is concerned) using patterns, or a combination.<\/p>\n

<\/p>\n

Patrick Dillon tackled the Pie Chart thing<\/h3>\n

Enhancing Charts With SVG Patterns<\/a>:<\/p>\n

When one of the slices is filled with something more than color, it’s easier to figure out [who the Independents are]:<\/p><\/blockquote>\n

See the Pen Political Party Affiliation – #2<\/a> by Patrick Dillon (@pdillon<\/a>) on CodePen<\/a>.<\/p>\n

Filling a pie slice with a pattern is not a common charting library feature (yet), but if your library of choice is SVG-based, you are free to implement SVG patterns.<\/p><\/blockquote>\n

As in, literally a <pattern \/><\/code> in SVG!<\/p>\n

Here’s a simple one for horizontal lines:<\/p>\n

<pattern \r\n    id=\"horzLines\" \r\n    width=\"8\" \r\n    height=\"4\" \r\n    patternUnits=\"userSpaceOnUse\">\r\n       <line \r\n          x1=\"0\" \r\n          y1=\"0\" \r\n          x2=\"8\" \r\n          y2=\"0\" \r\n         style=\"stroke:#999;stroke-width:1.5\" \r\n       \/>\r\n<\/pattern><\/code><\/pre>\n

Now any SVG element can use that pattern as a fill. Even strokes. Here’s an example of mixed usage of two simple patterns:<\/p>\n

See the Pen Simple Line Patterns<\/a> by Chris Coyier (@chriscoyier<\/a>) on CodePen<\/a>.<\/p>\n

That’s nice for filling SVG elements, but what about HTML elements?<\/p>\n

Irene Ros created Pattern Fills that are SVG based, but usable in CSS also.<\/h3>\n

Using SVG Patterns as Fills:<\/a><\/p>\n

\n

There are several ways to use Pattern Fills<\/a>:<\/p>\n