12.3. Setting a label
Labels are textual information you can display on vector features or maps. They add details you could not necessarily represent using symbols. Two types of text-related items are available in QGIS:
They can be used to render texts over the map (layout/map title, decorations, scale bar, …), usually through the font widget.
To create a Text Format item:
They are used to configure smart labelling for vector layers through the Labels tab of the vector Layer Properties dialog or Layer Styling panel or using the Layer Labeling Options button of the Label toolbar.
To create a Label Settings item:
Activate the Label Settings tab
The Label Settings dialog opens with the following properties. As usual, these properties are data-definable.
Most of the following properties are common to Text Format and Label Settings items.
the Font, from the ones available on your machine
the Style: along with the common styles of the font, you can set whether the text should be underlined or striked through
the Size in any supported unit
and the Opacity.
At the bottom of the tab, a widget shows a filterable list of compatible items stored in your style manager database. This allows you to easily configure the current text format or label setting based on an existing one, and also save a new item to the style database: Press the Save format… or Save settings… button and provide a name and tag(s).
When configuring a Label Settings item, text format items are also available in this widget. Select one to quickly overwrite the current textual properties of the label. Likewise, you can create/overwrite a text format from there.
Use the Type case option to change the capitalization style of the text. You have the possibility to render the text as:
Title case: modifies the first letter of each word into capital, and turns the other letters into lower case if the original text is using a single type case. In case of mixed type cases in the text, the other letters are left untouched.
Force first letter to capital: modifies the first letter of each word into capital and leaves the other letters in the text untouched.
Under Spacing, change the space between words and between individual letters.
Set the Text orientation which can be Horizontal or Vertical. It can also be Rotation-based when setting a label (e.g., to properly label line features in parallel placement mode).
Use the Blend mode option to determine how your labels will mix with the map features below them (more details at Modurile de Fuziune).
The Apply label text substitutes option allows you to specify a list of texts to substitute to texts in feature labels (e.g., abbreviating street types). Replacement texts are used when displaying labels on the map. Users can also export and import lists of substitutes to make reuse and sharing easier.
Configure Multiple lines:
Set a character that will force a line break in the text with the Wrap on character option
Set an ideal line size for auto-wrapping using the Wrap lines to option. The size can represent either the Maximum line length or the Minimum line length.
Decide the Line Height
Format the Alignment: typical values available are Left, Right, Justify and Center.
When setting point labels properties, the text alignment can also be Follow label placement. In that case, the alignment will depend on the final placement of the label relative to the point. E.g., if the label is placed to the left of the point, then the label will be right aligned, while if it is placed to the right, it will be left aligned.
The Multiple lines formatting is not yet supported by curve based label placement. The options will then be deactivated.
For line labels you can include Line direction symbol to help determine the line directions, with symbols to use to indicate the Left or Right. They work particularly well when used with the curved or Parallel placement options from the Placement tab. There are options to set the symbols position, and to Reverse direction.
Use the Formatted numbers option to format numeric texts. You can set the number of Decimal places. By default,
3decimal places will be used. Use the Show plus sign if you want to show the plus sign for positive numbers.
Set the buffer’s Size in any supported unit
Select the buffer’s Color
Color buffer’s fill: The buffer expands from the label’s outline, so, if the option is activated, the label’s interior is filled. This may be relevant when using partially transparent labels or with non-normal blending modes, which will allow seeing behind the label’s text. Unchecking the option (while using totally transparent labels) will allow you to create outlined text labels.
Define the buffer’s Opacity
Apply a Pen join style: it can be Round, Miter or Bevel
Use the Blend mode option to determine how your label’s buffer will mix with the map components below them (more details at Modurile de Fuziune).
Check Draw effects to add advanced paint effects for improving text readability, eg through outer glows and blurs.
a regular shape such as Rectangle, Square, Circle or Ellipse
an SVG symbol from a file, a URL or embedded in the project or style database (more details)
or a Marker Symbol you can create or select from the symbol library.
Depending on the selected shape, you need to configure some of the following properties:
The Size type of the frame, which can be:
Fixed: using the same size for all the labels, regardless the size of the text
or a Buffer over the text’s bounding box
The Size of the frame in X and Y directions, using any supported units
A Rotation of the background, between Sync with label, Offset of label and Fixed. The last two require an angle in degrees.
An Offset X,Y to shift the background item in the X and/or Y directions
A Radius X,Y to round the corners of the background shape (applies to rectangle and square shapes only)
An Opacity of the background
A Blend mode to mix the background with the other items in the rendering (see Modurile de Fuziune).
The Fill color, Stroke color and Stroke width for shape types other than the marker symbol. Use the Load symbol parameters to revert changes on an SVG symbol to its default settings.
A Pen join style: it can be Round, Miter or Bevel (applies to rectangle and square shapes only)
Draw effects to add advanced paint effects for improving text readability, eg through outer glows and blurs.
Indicate the item used to generate the shadow with Draw under. It can be the Lowest label component or a particular component such as the Text itself, the Buffer or the Background.
Set the shadow’s Offset from the item being shadowded, ie:
The angle: clockwise, it depends on the underlying item orientation
The distance of offset from the item being shadowded
The units of the offset
Influence the appearance of the shadow with the Blur radius. The higher the number, the softer the shadows, in the units of your choice.
Define the shadow’s Opacity
Rescale the shadow’s size using the Scale factor
Choose the shadow’s Color
Use the Blend mode option to determine how your label’s shadow will mix with the map components below them (more details at Modurile de Fuziune).
Other than the text formatting settings exposed above, you can also set how labels interact with each others or with the features.
To create masking effects on labels:
Then you can set:
Select this mask shape as a mask source in the overlapping layer properties Mask tab (see Masks Properties).
A common practice when placing labels on a crowded map is to use callouts - labels which are placed outside (or displaced from) their associated feature are identified with a dynamic line connecting the label and the feature. If one of the two endings (either the label or the feature) is moved, the shape of the connector is recomputed.
Select the Style of connector, one of:
Simple lines: a straight line, the shortest path
Manhattan style: a 90° broken line
Select the Line style with full capabilities of a line symbol including layer effects, and data-defined settings
Set the Minimum length of callout lines
Set the Offset from feature option: controls the distance from the feature (or its anchor point if a polygon) where callout lines end. Eg, this avoids drawing lines right up against the edges of the features.
Set the Offset from label area option: controls the distance from the label anchor point (where the callout line ends). This avoids drawing lines right up against the text.
Set the Anchor point for the (polygon) feature (the end point of the connector line). Available options:
Pole of inaccessibility
Point on exterior
Point on surface
Set the Label anchor point: controls where the connector line should join to the label text. Available options:
Fixed position at the edge (Top left, Top center, Top right, Left middle, Right middle, Bottom left, Bottom center and Bottom right).
Choose the Placement tab for configuring label placement and labeling priority. Note that the placement options differ according to the type of vector layer, namely point, line or polygon, and are affected by the global PAL setting.
Point labels placement modes available are:
Cartographic: point labels are generated with a better visual relationship with the point feature, following ideal cartographic placement rules. Labels can be placed:
at a set Distance in supported units, either from the point feature itself or from the bounds of the symbol used to represent the feature (set in Distance offset from). The latter option is especially useful when the symbol size isn’t fixed, e.g. if it’s set by a data defined size or when using different symbols in a categorized renderer.
following a Position priority that can be customized or set for an individual feature using a data defined list of prioritised positions. This also allows only certain placements to be used, so e.g. for coastal features you can prevent labels being placed over the land.
By default, cartographic mode placements are prioritised in the following order (respecting the guidelines from Krygier and Wood (2011) and other cartographic textbooks):
top, slightly right
bottom, slightly left.
Around Point: labels are placed in a circle around the feature. equal radius (set in Distance) circle around the feature. The placement priority is clockwise from the „top right”. The position can be constrained using the data-defined Quadrant option.
Offset from Point: labels are placed at an Offset X,Y distance from the point feature, in various units, or preferably over the feature. You can use a data-defined Quadrant to constrain the placement and can assign a Rotation to the label.
Label modes for line layers include:
Parallel: draws the label parallel to a generalised line representing the feature, with preference for placement over straighter portions of the line. You can define:
Allowed positions: Above line, On line, Below line and Line orientation dependent position (placing the label at the left or the right of the line). It’s possible to select several options at once. In that case, QGIS will look for the optimal label position.
Distance between the label and the line
Curved: draws the label following the curvature of the line feature. In addition to the parameters available with the Parallel mode, you can set the Maximum angle between curved characters, either inside or outside.
Horizontal: draws labels horizontally along the length of the line feature.
Next to placement modes, you can set:
Repeating Labels Distance to display multiple times the label over the length of the feature. The distance can be in
Meters at scale,
A Label Overrun Distance (not available for horizontal mode): specifies the maximal allowable distance a label may run past the end (or start) of line features. Increasing this value can allow for labels to be shown for shorter line features.
Label Anchoring: controls the placement of the labels along the line feature they refer to. Click on Settings … to choose:
the position along the line (as a ratio) which labels will be placed close to. It can be data-defined and possible values are:
Placement Behavior: use Preferred Placement Hint to treat the label anchor only as a hint for the label placement. By choosing Strict, labels are placed exactly on the label anchor.
You can choose one of the following modes for placing labels of polygons:
Offset from Centroid: labels are placed over the feature centroid or at a fixed Offset X,Y distance (in supported units) from the centroid. The reference centroid can be determined based on the part of the polygon rendered in the map canvas (visible polygon) or the whole polygon, no matter if you can see it. You can also:
force the centroid point to lay inside their polygon
place the label within a specific quadrant
assign a rotation
Allow placing labels outside of polygons when it is not possible to place them inside the polygon. Thanks to data-defined properties, this makes possible to either allow outside labels, prevent outside labels, or force outside labels on a feature-by-feature basis.
Around Centroid: places the label within a preset distance around the centroid, with a preference for the placement directly over the centroid. Again, you can define whether the centroid is the one of the visible polygon or the whole polygon, and whether to force the centroid point inside the polygon.
Horizontal: places at the best position a horizontal label inside the polygon. The preferred placement is further from the edges of the polygon. It’s possible to Allow placing labels outside of polygons.
Free (Angled): places at the best position a rotated label inside the polygon. The rotation respects the polygon’s orientation and the preferred placement is further from the edges of the polygon. It’s possible to Allow placing labels outside of polygons.
Using Perimeter: draws the label parallel to a generalised line representing the polygon boundary, with preference for straighter portions of the perimeter. You can define:
Allowed positions: Above line, On line, Below line and Line orientation dependent position (placing the label at the left or the right of the polygon’s boundary). It’s possible to select several options at once. In that case, QGIS will look for the optimal label position.
Distance between the label and the polygon’s outline
the Repeating Labels Distance to display multiple times the label over the length of the perimeter.
Using Perimeter (Curved): draws the label following the curvature of the polygon’s boundary. In addition to the parameters available with the Using Perimeter mode, you can set the Maximum angle between curved characters polygon, either inside or outside.
Outside Polygons: always places labels outside the polygons, at a set Distance
Some label placement settings are available for all layer geometry types:
The Data Defined group provides direct control on labels placement, on a feature-by-feature basis. It relies on their attributes or an expression to set:
the X and Y coordinate
the text alignment over the custom position set above:
Horizontal: it can be Left, Center or Right
the text Vertical: it can be Bottom, Base, Half, Cap or Top
the text Rotation. Check the Preserve data rotation values entry if you want to keep the rotation value in the associated field and apply it to the label, whether the label is pinned or not. If unchecked, unpinning the label rotation is reset and its value cleared from the attribute table.
Data-defined rotation with polygon features is currently supported only with the Around centroid placement mode.
In the Priority section you can define the placement priority rank of each label, ie if there are different diagrams or labels candidates for the same location, the item with the higher priority will be displayed and the others could be left out.
The priority rank is also used to evaluate whether a label could be omitted due to a greater weighted obstacle feature.
In some contexts (eg, high density labels, overlapping features…), the labels placement can result in labels being placed over unrelated features.
An obstacle is a feature over which QGIS avoids placing other features» labels or diagrams. This can be controlled from the Obstacles section:
Use the Settings button to tweak the obstacle’s weighting.
For every potential obstacle feature you can assign an Obstacle weight: any label or diagram whose placement priority rank is greater than this value can be placed over. Labels or diagrams with lower rank will be omitted if no other placement is possible.
This weighting can also be data-defined, so that within the same layer, certain features are more likely to be covered than others.
For polygon layers, you can choose the kind of obstacle the feature is:
over the feature’s interior: avoids placing labels over the interior of the polygon (prefers placing labels totally outside or just slightly inside the polygon)
or over the feature’s boundary: avoids placing labels over the boundary of the polygon (prefers placing labels outside or completely inside the polygon). This can be useful for layers where the features cover the whole area (administrative units, categorical coverages, …). In this case, it is impossible to avoid placing labels within these features, and it looks much better when placing them over the boundaries between features is avoided.
Under Label options:
You find the scale-based and the Pixel size-based visibility settings.
The Label z-index determines the order in which labels are rendered, as well in relation with other feature labels in the layer (using data-defined override expression), as with labels from other layers. Labels with a higher z-index are rendered on top of labels (from any layer) with lower z-index.
Additionally, the logic has been tweaked so that if two labels have matching z-indexes, then:
if they are from the same layer, the smaller label will be drawn above the larger label
if they are from different layers, the labels will be drawn in the same order as their layers themselves (ie respecting the order set in the map legend).
This setting doesn’t make labels to be drawn below the features from other layers, it just controls the order in which labels are drawn on top of all the layers» features.
While rendering labels and in order to display readable labels, QGIS automatically evaluates the position of the labels and can hide some of them in case of collision. You can however choose to Show all labels for this layer (including colliding labels) in order to manually fix their placement (see The Label Toolbar).
With data-defined expressions in Show label and Always Show you can fine tune which labels should be rendered.
Allow to Show upside-down labels: alternatives are Never, when rotation defined or always.
Under Feature options:
You can choose to Label every part of a multi-part features and Limit number of features to be labeled to.
Both line and polygon layers offer the option to set a minimum size for the features to be labeled, using Suppress labeling of features smaller than.
For polygon features, you can also filter the labels to show according to whether they completely fit within their feature or not.
For line features, you can choose to Merge connected lines to avoid duplicate labels, rendering a quite airy map in conjunction with the Distance or Repeat options in the Placement tab.