GeoServer CSS module: style in style
OpenGeo is excited to share the GeoServer CSS module, an alternative to SLD for thematic map styling in the OpenGeo Suite. Compared to SLD, GeoServer CSS brings many advantages for web cartographers.
GeoServer CSS is customized for use in GeoServer and provides access to spatial utilities such as powerful filter expressions that are useful not only for choosing which features to render but also for transforming geometries and other attributes on-the-fly during the rendering process. Thanks to its custom syntax (which builds on OGC CQL the same way that SLD builds on OGC Filter Encoding XML) it is much more compact, allowing authors to see more of the style without scrolling and to make edits without worrying about details such as closing nested XML tags in the proper order. GeoServer CSS is also simpler because it eschews some non-styling aspects of SLD such as embedded geometries.
As an example, let’s say we are styling polygons representing the habitats of several bird species. We would like to distinguish species by color (orioles have an orange area, bluebirds have a blue one, etc.), but all polygons should have a consistent opacity to help us identify places where habitats overlap. A style in CSS notation might look like this:
[species="bluebird"] {
fill: blue;
fill-opacity: 70%;
}
[species="oriole"] {
fill: orange;
fill-opacity: 70%;
}
[species="robin"] {
fill: brown;
fill-opacity: 70%;
}
Whereas in SLD, we might write the following much more verbose style:
<?xml version="1.0" encoding="UTF-8"?>
<sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
<sld:FeatureTypeStyle>
<sld:Name>name</sld:Name>
<sld:Rule>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>species</ogc:PropertyName>
<ogc:PropertyName>oriole</ogc:PropertyName>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">#ffa500</sld:CssParameter>
<sld:CssParameter name="fill-opacity">0.7</sld:CssParameter>
</sld:Fill>
</sld:PolygonSymbolizer>
</sld:Rule>
<sld:Rule>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>species</ogc:PropertyName>
<ogc:PropertyName>robin</ogc:PropertyName>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">#ff000</sld:CssParameter>
<sld:CssParameter name="fill-opacity">0.7</sld:CssParameter>
</sld:Fill>
</sld:PolygonSymbolizer>
</sld:Rule>
<sld:Rule>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>species</ogc:PropertyName>
<ogc:PropertyName>bluebird</ogc:PropertyName>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">#0000ff</sld:CssParameter>
<sld:CssParameter name="fill-opacity">0.7</sld:CssParameter>
</sld:Fill>
</sld:PolygonSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
Where SLD would require all style properties to be listed for each rule in the style, the “cascading” nature of CSS allows styles to specify common attributes in one place. This allows styles to be written in a less repetitive way, reducing the amount of work needed to create styles and making it easier to ensure consistency between multiple rules. The repeated property “fill-opacity: 70%” in the example above presents a problem when updating the style—it’s extra work for a web cartographer to ensure that the fill is applied consistently across all styles. While it doesn’t save us much typing (although compared to SLD we are already way ahead!) we can change opacities across the entire style by editing in just one place. For example, we could “factor out” the opacity to a catch-all rule:
* {
fill-opacity: 70%;
}
[species="bluebird"] {
fill: blue;
}
[species="oriole"] {
fill: orange;
}
[species="robin"] {
fill: brown;
}
GeoServer CSS is inspired by the web—and by great tools like Carto, Cascadenik, and MapCSS. Like these tools it provides a concise styling syntax modeled on CSS but differs in that it’s goal is to improve the experience relative to SLD while preserving CSS concepts like cascading. While we ultimately aspire to a common CSS-like styling language for web cartography, we hope that GeoServer CSS is much easier than SLD and will be familiar enough for web designers to use.
We’re excited about GeoServer CSS and think it makes building maps easier, We’d like you to try it out and tell us what you think. If it’s well-received, we may include it in a future release of the OpenGeo Suite. We encourage you to download and install the plugin, and if you have any questions, be sure to read the documentation or look for dwins in the #geoserver IRC channel on Freenode.

Wow, yet another geo-css styling language !
I really think it’s time for a common effort to standardize something…
Oh and adding to the cited ones, we also have osgearth css styling :
http://www.osgearth.org/wiki/FeatureSymbology
is Translator.css2sld still supported if there is a reason to migrate a data set to different technology that requires an SLD?
Vincent, some work has already been done toward unifying the different spatial CSS variants that are currently out there. You can see the work that’s already been done at https:/github.com/nvkelso/carto-css-map-styling/ . It is probably going to be some time before any implementation of this specification exists, however.
els, yes, the CSS styles are translated to SLD files on disk as they have always been. A future change might use direct-from-css rendering as a performance improvement, but I am interested in maintaining SLD export for the time being.
Hi!
I’m actually trying to get the css plugin working in my opengeo suite installation under ubuntu 12.04, but the “Map CSS Demo” link is not appearing in my geoserver web interface. I installed it like described into /usr/share/opengeo-suite/geoserver/WEB-INF/lib/.
Can someone help?
Hi Daniel,
Thanks for reaching out; I’m sorry you’re having an issue with the CSS plug-in. I’ve talked to one of our developers who is familiar with the issue. For now your best bet is to downgrade to suite 2.5, you shouldn’t run into the issue with the slightly older version. We’ll be looking into a more permanent fix for this in the near future.