Examine an existing style

  1. From the GeoServer Welcome Page navigate to Styles.


    Navigating to Style configuration

  2. From the styles list select the citylimits style


    The styles list

  3. Inside the Style Editor we have the following style:

    <?xml version="1.0" encoding="UTF-8"?>
    <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
            <sld:Name>group 0</sld:Name>
                  <sld:CssParameter name="fill">#7F7F7F</sld:CssParameter>
                  <sld:CssParameter name="fill-opacity">0.5</sld:CssParameter>
                  <sld:CssParameter name="stroke">#7F7F7F</sld:CssParameter>
                  <sld:CssParameter name="stroke-opacity">0.5</sld:CssParameter>
                  <sld:CssParameter name="stroke-width">2.0</sld:CssParameter>
                  <sld:CssParameter name="font-family">Arial</sld:CssParameter>
                  <sld:CssParameter name="font-size">14.0</sld:CssParameter>
                  <sld:CssParameter name="font-style">normal</sld:CssParameter>
                  <sld:CssParameter name="font-weight">normal</sld:CssParameter>
                  <sld:CssParameter name="fill">#000000</sld:CssParameter>
                <sld:VendorOption name="maxDisplacement">200</sld:VendorOption>
                <sld:VendorOption name="group">true</sld:VendorOption>


    The most important section are:

    • The <Rule> tag combines a number of symbolizers (we have also the possibility to define the OGC filter) to define the portrayal of a feature.

    • The <PolygonSymbolizer> styles polygons and contain styling information about their border (stroke) and their fill.

    • The <TextSymbolizer > specifies text labels and their style:

      • <Label> Specifies the content of the text label
      • <Font> Specifies the font information for the labels.
      • <LabelPlacement> Sets the position of the label relative its associate feature.
      • <Fill> Determines the fill color of the text label.
      • VendorOption maxDisplacement Controls the displacement of the label along a line. Normally GeoServer would label a polygon in its centroid, provided the location is not busy with another label and that the label is not too big compare to the polygon, or not label it at all otherwise. When the maxDisplacement is set, the labeller will search for another location within maxDisplacement pixels from the pre-computed label point.
      • VendorOption Group Sometimes you will have a set of related features that you only want a single label for. The grouping option groups all features with the same label text, then finds a representative geometry for the group.
    • The <MaxScaleDenominator> and <MinScaleDenominator> are used to apply a particular SLD rule to a specific scale. The above SLD makes sure that the Boulder border disappear once we zoom in enough to see the city details. An alternative approach could be to keep the layer showing, but switch it to a different style, for example a think red line, so that the details of the city are not disturbed by the polygon fill.

  4. Now, back to the style list, select the rivers style.

  5. Inside the Style Editor we have the following style:

    <?xml version="1.0" encoding="UTF-8"?>
    <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
          <sld:Name>Hydrology Line</sld:Name>
              <sld:Name>default rule</sld:Name>
                  <sld:CssParameter name="stroke-width">0.5</sld:CssParameter>
                  <sld:CssParameter name="stroke">#06607F</sld:CssParameter>


    This is a very simple Line style. Take into account the LineSymbolizer that styles lines. Lines are one-dimensional geometry elements that contain position and length. Lines can be comprised of multiple line segments.

    The outermost tag is the <Stroke> tag. This tag is required, and determines the visualization of the line:

    • stroke Specifies the solid color given to the line, in the form #RRGGBB. Default is black (#000000).
    • stroke-width Specifies the width of the line in pixels. Default is 1.

    In this case MaxScaleDenominator is used to make sure that the rivers start showing up when we are zoomed in enough, and in particular as the city borders disappear

Create a simple style for points

  1. From the GeoServer Welcome Page navigate to Style.


    Navigating to Style configuration

  2. Click New


    Adding a new style

  3. Enter “landmarks” in the Name field and select “SLD” in the Format field.


    Creating a new style

  4. In the SLD Editor enter the following XML:

    <StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
          <Title>Point Landmarks</Title>
                       <CssParameter name="fill">#009900</CssParameter>
                       <CssParameter name="fill-opacity">0.2</CssParameter>
                       <CssParameter name="stroke">#000000</CssParameter>
                       <CssParameter name="stroke-width">2</CssParameter>


    Take into account:

    • WellKnownName The name of the common shape. Options are circle, square, triangle, star, cross, or x. Default is square.
      • fill Specifies how the symbolizer should be filled. Options are a <CssParameter name="fill"> specifying a color in the form #RRGGBB, or <GraphicFill> for a fill made with a repeated graphic.
      • fill-opacity Determines the opacity (transparency) of symbolizers. Values range from 0 (completely transparent) to 1 (completely opaque). Default is 1.
  5. Then click Save button.

  6. Open the geosolutions:bptlandmarks vector layer, but this time associate the style as an “Additional Style”:


    Open the Edit Layers, Publishing tab

  7. Click on the Save button.

  8. Preview the geosolutions:bptlandmarks layer, which with the default style should be empty due to scale dependencies. Then click the option button at the top left of the map and select the landmarks style in the style drop down:


    Open the Layers Preview

Create the same style with CSS

  1. Create a new style named landmarks_css and select the CSS format.

  2. Paste the following in the Style Editor:

    * {
        mark: symbol(triangle);
        mark-size: 12;
        :nth-mark(1) {
            fill: #009900;
            fill-opacity: 0.2;
            stroke: #000000;
            stroke-width: 2;
  3. Save the style

  4. Open the geosolutions:bptlandmarks vector layer and associate the new style as an “Additional Style”

  5. Preview the geosolutions:bptlandmarks layer and select the new landmarks_css style

  6. The style appears identical to the SLD one


Useful additional CSS documentation could be found at the following links: