Home / GIS and Open Map Data for Beginners

Rule-Based Symbology in QGIS: Styles Written as Conditions

Abstract top view of a Vienna city map with artistic paper cutouts

Photo: Marco Sebastian Mueller / Pexels

Every QGIS layer gets styled somehow, and for most layers the simple renderers suffice: one symbol for everything, a color per category, a ramp across a number. Then a real layer arrives, roads that must draw by class and zoom, land use whose exceptions matter more than its classes, and the simple renderers start lying by omission. The renderer built for that day is Rule-based: the style becomes a list of rules, each rule a filter expression married to a symbol, evaluated in order, nestable, with a catch-all for whatever the rules forgot. It is the most expressive styling QGIS offers, and the one whose failure modes are invisible until you learn them. This guide teaches the renderer as a working system, with a complete worked style you can adapt.

Interactive tool

Rules That Draw: The Rule-Based Styling Checklist

Check off each step as you finish it. Your progress stays on this page.

0 of 7 complete

0% done

The Renderer Model in One Paragraph

QGIS styling has three levels, and rule-based symbology lives at the top one. A renderer decides which symbol each feature gets; a symbol is a stack of symbol layers that draw together; data-defined overrides can drive individual symbol properties by expression. The simple renderers decide by one field's value. The rule-based renderer decides by any expression you can write: fields combined, geometry measured, scale consulted. That freedom is the entire point, and the expression builder, the dialog behind every expression in QGIS, is the workbench where rules are written. If expressions are new to you, that guide is the prerequisite; this one assumes you can write a filter and teaches you to govern a set of them.

Building the First Rule Set: A Roads Layer

Open the layer's Properties, Symbology tab, and switch the renderer dropdown from Single Symbol to Rule-based. The panel becomes a rule list. Each rule has a label (for humans), a filter (for the machine), and a symbol (for the map). A starter set for a roads layer, in the order it should be written:

LabelFilterSymbol
Motorways"highway" = 'motorway'Wide orange casing, bold
Primary roads"highway" = 'primary'Solid warm yellow, medium
Residential"highway" = 'residential'Thin white with gray casing
Tracks"highway" = 'track'Dashed brown, hairline
Everything elseELSEPale gray, thin

Build each rule with the plus button, write its filter in the expression editor, and click its symbol swatch to design the symbol itself. Three lessons arrive with the first working set. First, a feature matching no rule does not draw at all, unless an ELSE rule catches it, which is why the table ends with one. Second, the filters are the style: the symbol work is ordinary, and all the intelligence sits in the expressions. Third, labels are documentation: six months from now, the label column is the only explanation of intent the file contains, so write labels for the reader you will be.

Tablet displaying a 3D map surrounded by drone and camera gear on a desk
Tablet displaying a 3D map surrounded by drone and camera gear on a desk

Rule Order and the ELSE Discipline

Rules evaluate in list order, and a feature takes the first rule it matches at each level. Order is therefore meaning: specific rules above general ones, or the general rule swallows the specifics whole. A rule for "highway" = 'motorway' AND "tunnel" = 'yes' (dim the motorway in tunnels) must sit above the plain motorway rule, or it will never fire. The ELSE rule is the order system's keystone: it matches whatever no earlier rule claimed, and it converts the renderer's most dangerous property, silent invisibility, into a visible decision. Style ELSE deliberately: a quiet gray that says "present but unclassified" on a working map, or a loud magenta on a debugging map, whose entire job is to show you what your rules failed to anticipate. Features vanishing from a map is the classic rule-based bug report, and nine times in ten the diagnosis is a missing ELSE and the cure is adding one and reading what it catches.

Nesting: Rules Inside Rules

Rules can carry child rules, and nesting is how real styles stay readable. Take the land use layer: a top-level rule per broad class (woodland, water, farmland, urban), each with children refining it, woodland splitting into coniferous and broadleaf by a second field, urban splitting by density. A feature descends the tree: it must match the parent to reach the children, and the children inherit the parent's context, so their filters can be short, concerned only with their own distinction. The discipline mirrors the dissolve lesson from the merge polygons guide: structure the grouping deliberately, because the structure is the analysis. Flat lists of forty rules are how styles rot; two levels of honest nesting are how they survive their author.

Scale Ranges: Rules That Know the Zoom

Each rule carries optional minimum and maximum scales, and with them a style can tell the truth at every zoom: motorways labeled and cased at regional scales, tracks appearing only when the map is close enough for them to be information rather than noise, minor classes retiring as the view widens. Scale ranges are the difference between a style that works in the demo and one that works in the atlas, and they are set per rule in the same panel, a range slider beside the filter. The professional pattern pairs them with the rule order: as the map zooms out, whole subtrees switch off together, and the map thins by design rather than by clutter.

Converting and Saving: Styles as Assets

Two closing operations turn a rule set from a session into an asset. A categorized or graduated style can be converted to rule-based (the renderer dropdown offers the conversion, carrying the classes across as rules), which is the standard growth path: start simple, convert when the exceptions arrive, then refine the rules the conversion wrote. And the finished style saves as a QML file from the layer's Style menu, a portable document that applies the whole rule set to another layer with the same fields in one action. Teams keep QML libraries the way they keep code, because that is what a rule set is: cartographic code, reviewed, versioned, and reused. The Python console can build and apply styles programmatically as well, for the day the same rules must land on forty layers before lunch.

A Second Worked Style: Land Use With Exceptions

Roads flatter the renderer, because road classes are tidy. Land use is the honest test, and a compact version shows the nesting and the ELSE earning their keep together. The layer is a regional land use set with a class field (woodland, water, farmland, urban, wetland) and a protected flag:

  • Protected land (parent rule: "protected" = 'yes'), drawn with a green hatch overlay whatever its class, because protection is the map's argument; children split it by class for the fill beneath the hatch.
  • Water: "class" = 'water', a flat blue, no children needed.
  • Woodland: "class" = 'woodland', children for "type" = 'coniferous' (dark, dense) and "type" = 'broadleaf' (light, warm), and an ELSE child in the parent's green family for the woodland rows whose type the data never recorded.
  • Farmland and urban: single rules each, farmland by a pale straw, urban by a quiet gray that recedes.
  • ELSE at the top level, in the debugging magenta until the map ships, then in a neutral tone: whatever the survey invents next lands here, visible, instead of vanishing.

Read the style as a paragraph and it argues the map's thesis in order: protection first, then the elements, then the matrix of farm and town, then the honest remainder. That readability is not a luxury. The next analyst, the reviewer, the future you, reads the rule list the way a programmer reads code, and a style that reads well is a style that gets corrected instead of replaced.

Symbol Levels: The Drawing Order Inside a Symbol

One refinement separates polished rule-based work from adequate work, and it lives a level down: symbol levels. A road symbol is a stack, casing below, fill above, and when two roads cross, the stacks interleave by default in ways that break the junction's illusion: one road's casing can slice across another's fill. Symbol levels, enabled in the layer's rendering panel, assign each symbol layer a drawing rank across the whole layer, so all casings draw before all fills and junctions knit together the way printed maps have always drawn them. Rule-based styles need this more than simple ones, because a rule set's whole purpose is a hierarchy of roads, and a hierarchy whose junctions tear looks broken at exactly the places the eye checks first. Set the levels once, casing lowest, fills above, centerline dashes and shields at the top, and the style's intelligence survives contact with its own intersections.

Debugging a Style That Lies

When a rule-based map misbehaves, the suspects are few and the order of interrogation is fixed. A feature is missing: it matched no rule and no ELSE exists, or its rule's scale range excludes the current zoom. A feature wears the wrong symbol: an earlier, broader rule claimed it first; reorder, or narrow the earlier filter. Everything is the ELSE color: the filters reference a field name or value the data does not contain, a spelling drift between the style and the layer, which the expression editor's field list exposes in seconds. The map crawls: forty rules with expensive expressions over a million features is real work; simplify the hot filters, or push the classification into a field once, with the field calculator, and let the rules read a finished value. Each failure is legible once the model, order, ELSE, scale, is in your head, which is the actual content of this guide: the panel is small, and the model is the skill.

Related Guides

If this page answered part of the question, these GIS and open data guides cover the rest of the same ground:

Frequently Asked Questions

What is rule-based symbology in QGIS?

A renderer in which each feature's symbol is chosen by rules: filter expressions paired with symbols, evaluated in order. Unlike categorized styling, which matches one field's values, a rule's filter can combine any fields and conditions, rules can nest, and an ELSE rule catches features no other rule matches.

Why did some features disappear when I switched to rule-based?

Because a feature that matches no rule is not drawn. Add an ELSE rule, which catches everything unmatched, and style it visibly while you work: what it catches is the list of cases your rules have not considered yet.

Does rule order matter?

Yes. A feature takes the first rule it matches at each level, so specific rules must sit above general ones. A detailed rule placed below a broad one that also matches will never fire. Nesting works the same way: children are only reached through a matching parent.

Can rules change with zoom level?

Yes. Each rule has optional minimum and maximum scale settings. Tracks can appear only at large scales, minor classes can retire as the map zooms out, and whole subtrees can switch off together, keeping the map honest at every zoom.

How do I reuse a rule-based style on another layer?

Save it as a QML style file from the layer's Style menu, then load that style onto any layer with matching fields. A categorized style can also be converted into rules as a starting point, then refined.

Photo credits: Marco Sebastian Mueller (Pexels); Amar Preciado (Pexels). Photos are served from this site; follow the credit to the library page for the original.