I am using GetLegendGraphic to fill my legend in a leaflet map. I use CSS to style my layer on Geoserver but I have trouble to add the title to my legend graphic. This code work and add an explanatory text next to the graphic.

* {
  mark: symbol('square');
  mark-size: 12px;

/* @title Fixed */
:mark[recent=true] {
  fill: yellow;
  stroke: yellow;

/* @title Faulty */
:mark[recent= false] {
  fill: blue;
  stroke: blue;

This one does not?

* {
    mark: symbol(circle);
    mark-size: 17px;

/* @title Planed */
:mark {
    fill: #51A02C;
    stroke: black;

This is my current output. They grey box is however undesired and probably come from an potential "null" value (No null value in the data set though). enter image description here

Any ideas how this could work? I would like to use CSS instead of SLD because some rules are hairy to write in SLD.

  • can you show us what is produced in each case
    – Ian Turton
    Aug 12, 2016 at 13:46

3 Answers 3


Checked again, I finally noted the issue is in the GetLegendGraphic response. The default behavior is that if there is a single rule in the output GeoServer won't add the title, assuming the client will do the labelling instead, while there are multiple ones, the title is always added, because the client cannot do so in an intelligent way.

This is documented here, see the "forceLabels" parameter: http://docs.geoserver.org/2.8.x/en/user/services/wms/get_legend_graphic/legendgraphic.html

This request:



enter image description here


I also had the problem with the legend and I solved it like this

[status = 'Gemeld'] { mark: symbol(circle);
[status = 'In behandeling'] { mark: symbol(circle);
[status = 'Afgehandeld' ] {mark: symbol(triangle);

/* @title Gemeld */
[status = 'Gemeld'] :mark {
fill: red;
size: 8;

/* @title In behandeling */ 
[status = 'In behandeling'] :mark {
fill: orange;
size: 8;
stroke: black 
/* @title  Afgehandeld*/
[status = 'Afgehandeld'] :mark {
fill: orange;
size: 12;
stroke: black;  

It gives this legend:

It gives this legend


It's probably a simple bug in the translator, but the second example can be equivalently expressed as:

/* @title Planed */ * { mark: symbol(circle); mark-size: 17px; }

:mark { fill: #51A02C; stroke: black; }

Doesn't that work?

  • Unfortunately not, just re-tried that variation
    – geogrow
    Aug 12, 2016 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.