Styles & SLD Reference

A comprehensive guide to defining, managing, and deploying Styled Layer Descriptors (SLD) in GeoServer. Covers syntax, symbolizers, filters, and best practices for production cartography.

Overview

GeoServer uses the OGC Styled Layer Descriptor (SLD) 1.0/1.1 standard to define how geographic features are rendered. SLD is an XML-based language that decouples data from visual presentation, enabling reusable, platform-independent map styling.

Note GeoServer supports both SLD 1.0 and 1.1. SLD 1.1 introduces improved raster styling, non-spatial symbolizers, and better filter expressions. For new projects, SLD 1.1 is recommended.

SLD Document Structure

An SLD file follows a strict hierarchical structure. The root element <StyledLayerDescriptor> contains one or more <NamedLayer> or <UserLayer> elements, each wrapping a <NamedStyle> with the actual rendering rules.

<StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
                       version="1.1.0">
  <NamedLayer>
    <Name>cities</Name>
    <UserStyle>
      <Title>City Population</Title>
      <FeatureTypeStyle>
        <Rule>
          <Name>large-city</Name>
          <Title>Population > 1M</Title>
          <Filter>
            <><PropertyName>pop</PropertyName> 1000000</></Filter>
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>circle</WellKnownName>
                <Fill><CssParameter name="fill">#38bdf8</CssParameter></Fill>
                <Stroke><CssParameter name="stroke">#0f172a</CssParameter></Stroke>
              </Mark>
              <Size>12</Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Core Style Components

SLD styling is built around Symbolizers. Each geometry type (Point, Line, Polygon, Raster, Text) has corresponding symbolizer tags that define visual properties.

PointSymbolizer

Defines markers, shapes, and external graphics for point features. Supports WellKnownName and ExternalGraphic with size, opacity, and rotation.

LineSymbolizer

Controls stroke width, color, dash patterns, and join/cap styles. Supports multiple <Stroke> elements for layered effects.

PolygonSymbolizer

Manages fills and strokes for areas. Fill supports solid colors, gradients, and hatch patterns. Stroke follows line styling rules.

TextSymbolizer

Handles feature labeling. Defines font family, size, placement, halo, and priority. Supports dynamic attribute binding via <Label>.

Filters & Dynamic Styling

SLD filters use the Filter Encoding (FE) standard to conditionally apply rules. Filters evaluate feature attributes to determine which symbolizers render.

Filter TypeUse CaseExample Syntax
ComparisonAttribute thresholds<PropertyIsGreaterThan>
LogicalAND/OR/NOT combinations<And>, <Or>, <Not>
SpatialGeometry intersections<Intersects>, <Within>
FunctionMath/string operations<Function name="format">

Tip Use <Function name="env"><ogc:Literal>SCALE_DENOMINATOR</ogc:Literal></Function> to create scale-dependent styling that adapts to zoom levels.

Advanced Techniques

External Graphics & SVGs

GeoServer supports inline SVGs and external image references. For production, use absolute URLs or deploy graphics to the GeoServer www/ directory.

<Graphic>
  <ExternalGraphic>
    <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
                     xlink:type="simple"
                     xlink:href="https://maps.example.com/icons/factory.svg"/>
    <Format>image/svg+xml</Format>
  </ExternalGraphic>
  <Opacity>0.8</Opacity>
</Graphic>

Layer-Dependent Colors & Opacity

Dynamic styling can reference feature attributes directly. This is essential for choropleth maps, heatmaps, and real-time sensor visualization.

<Fill>
  <CssParameter name="fill">
    <Function name="rgb">
      <Function name="mapScale">
        <PropertyName>pollution_index</PropertyName>
        <Parameter>0, 50, 50</Parameter>
        <Parameter>50, 200, 200</Parameter>
        <Parameter>100, 255, 50</Parameter>
      </Function>
    </Function>
  </CssParameter>
</Fill>

Best Practices