Introduction
GeoServer uses Styled Layer Descriptor (SLD) to visualize geospatial data. SLD is a XML-based standard created by the Open Geospatial Consortium (OGC). For more information on the SLD schema, please see the OGC page on Styled Layer Descriptor at http://www.opengeospatial.org/standards/sld.
SLD structure
An SLD file contains the following hierarchical structure:
- Header
- FeatureTypeStyles
- Rules
- Symbolizers
The header of the SLD contains metadata about XML namespaces, and is usually identical among different SLDs. The details of the header are beyond the scope of this workshop.
A FeatureTypeStyle is a group of styling rules. (Recall that a featuretype is another word for a layer.) Grouping by FeatureTypeStyle affects rendering order; the first FeatureTypeStyle will be rendered first, followed by the second, etc.
A Rule is a single styling directive. It can apply globally to a layer, or it can have filter logic associated with it so that the rule is conditionally applied. These conditions can be based on the attributes of the data, or based on the scale (zoom) level of the data being rendered.
A Symbolizer is the actual style instruction. There are five types of symbolizers:
- PointSymbolizer
- LineSymbolizer
- PolygonSymbolizer
- RasterSymbolizer
- TextSymbolizer
There can be one or more FeatureTypeStyles per SLD, one or more Rules per FeatureTypeStyles, and one or more Symbolizers per Rule.
Example
<?xml version="1.0" encoding="ISO-8859-1"?> <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <NamedLayer> <Name>Simple Point</Name> <UserStyle> <Title>Simple Point</Title> <FeatureTypeStyle> <Rule> <PointSymbolizer> <Graphic> <Mark> <WellKnownName>circle</WellKnownName> <Fill> <CssParameter name="fill">#FF0000</CssParameter> </Fill> </Mark> <Size>6</Size> </Graphic> </PointSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>
The first 11 lines are the header, which contain XML namespace information, as well as the Name and Title of the SLD. The actual styling happens inside the <FeatureTypeStyle> tag (lines 12-26), of which there is only one in this example. The tag contains one <Rule> (lines 13-25) and the rule contains one symbolizer, a <PointSymbolizer> (lines 14-24). The symbolizer directive creates a graphic mark of a “well known name”, in this case a circle (line 17). This shape has a <Fill> parameter of #FF0000 (line 19), which is an RGB color code for 100% red. The shape also has a <Size> of 6 (line 22), which is the diameter of the circle in pixels.

