CSS marker-mid Property
The CSS marker-mid property specifies an SVG marker graphic to display at intermediate vertices along supported SVG shapes and paths.
It is useful for highlighting points where path segments meet, adding directional symbols, and identifying connections in SVG diagrams. Markers are defined using the SVG <marker> element and referenced through the CSS url() function.
marker-mid Syntax
The marker-mid property accepts none or a URL reference to an SVG marker definition. CSS-wide keywords are also supported.
Basic Syntax
selector {
marker-mid: url(#marker-id);
}
Circle Marker
polyline {
marker-mid: url(#circle-marker);
}
Arrow Marker
path {
marker-mid: url(#arrow-marker);
}
Remove Intermediate Markers
path {
marker-mid: none;
}
CSS-Wide Keywords
path {
marker-mid: initial;
}
path {
marker-mid: inherit;
}
path {
marker-mid: unset;
}
path {
marker-mid: revert;
}
path {
marker-mid: revert-layer;
}
The initial value of marker-mid is none.
Property Values
| Value | Description |
|---|---|
none |
Displays no markers at intermediate vertices. |
url() |
References an SVG <marker> definition to display at intermediate vertices. |
initial |
Resets the property to its initial value of none. |
inherit |
Inherits the computed marker reference from the parent element. |
unset |
Behaves like inherit because the property is inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | Yes |
| Applies to | Supported SVG graphics elements, including paths, polylines, and polygons |
| Computed value | Specified keyword or absolute URL reference |
| Animation type | Discrete |
| Shorthand property | marker |
| Marker position | Intermediate vertices between path segments |
| Common use | SVG diagrams, connection points, and path decorations |
How It Works
The marker-mid property places a reusable SVG graphic at intermediate vertices where consecutive path segments meet. It does not place markers at the starting or ending vertices of an open path.
The browser determines marker positions from the SVG geometry. The marker's reference point and orientation control how its graphic aligns with each vertex.
HTML Example
<svg viewBox="0 0 300 120" xmlns="http://www.w3.org/2000/svg">
<defs>
<marker id="point-marker" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="10" markerHeight="10" markerUnits="userSpaceOnUse">
<circle cx="5" cy="5" r="4" fill="#f97316" />
</marker>
</defs>
<polyline class="marked-path" points="20,90 90,25 160,90 230,25 280,70" fill="none" stroke="#2563eb" stroke-width="3" />
</svg>
CSS Example
.marked-path {
marker-mid: url(#point-marker);
}
The orange circles appear at the three intermediate vertices of the polyline. The first and last points do not receive markers.
Important Consideration
The property does not create additional vertices or distribute markers evenly along a path. It uses the existing SVG geometry.
Defining Mid Markers
SVG markers are defined using the <marker> element, usually inside an SVG <defs> container. The marker's id is referenced by the CSS property.
Circle Marker Definition
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<marker id="middle-circle" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="10" markerHeight="10" markerUnits="userSpaceOnUse">
<circle cx="5" cy="5" r="4" fill="#f97316" />
</marker>
</defs>
</svg>
Reference the Marker
polyline {
marker-mid: url(#middle-circle);
}
Arrow Marker Definition
<marker id="middle-arrow" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#2563eb" />
</marker>
Reference the Arrow Marker
path {
marker-mid: url(#middle-arrow);
}
Common Marker Attributes
| Attribute | Description |
|---|---|
id |
Identifies the marker for CSS URL references. |
viewBox |
Defines the marker's internal coordinate system. |
refX |
Sets the horizontal reference point aligned with each vertex. |
refY |
Sets the vertical reference point aligned with each vertex. |
markerWidth |
Defines the marker viewport width. |
markerHeight |
Defines the marker viewport height. |
markerUnits |
Controls how marker dimensions are measured. |
orient |
Controls marker rotation at each vertex. |
Important Consideration
Marker definitions must be accessible to the SVG elements referencing them. An incorrect marker ID or invalid URL prevents the intended graphic from rendering.
Marker Placement
The marker-mid property places markers at intermediate vertices. The number and location of those vertices depend on the SVG shape.
Line
<line x1="20" y1="50" x2="220" y2="50" />
A straight SVG line has only a starting and ending vertex. It has no intermediate vertices, so marker-mid does not display a marker.
Polyline
<polyline points="20,80 80,20 140,80 200,20" />
This polyline has four vertices. Markers appear at the two intermediate points, 80,20 and 140,80.
Polygon
<polygon points="100,10 180,80 20,80" />
A polygon is closed. Intermediate markers appear at its vertices, including the vertices where connected segments meet around the closed shape.
Path
<path d="M 20 80 L 100 20 L 180 80" />
The path has one intermediate vertex at 100,20, where the two line segments meet.
Multiple Subpaths
<path d="M 20 80 L 80 20 L 140 80 M 180 80 L 240 20 L 300 80" />
Each subpath is evaluated separately. Intermediate markers appear at the vertices between segments within each subpath.
Curved Paths
<path d="M 20 90 Q 100 10 180 90 L 280 40" />
A marker can appear where the quadratic curve ends and the following line segment begins. The curve's control point is not an intermediate marker vertex.
Important Consideration
Intermediate markers are determined by segment boundaries, not by every visible bend or mathematical point along a curve.
Marker Orientation
The SVG orient attribute controls how markers rotate at intermediate vertices. This is particularly useful when placing directional arrows along a path.
Automatic Orientation
<marker id="auto-arrow" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#2563eb" />
</marker>
With orient="auto", the browser calculates the marker's direction using the incoming and outgoing path segments. At a corner, it generally uses the bisector of the segment directions.
Fixed Orientation
<marker id="fixed-arrow" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="45">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#2563eb" />
</marker>
The marker uses a fixed 45-degree rotation rather than following the path geometry.
Automatic Start-Reverse Orientation
<marker id="reverse-arrow" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#2563eb" />
</marker>
The auto-start-reverse value behaves like auto for intermediate markers. Its additional reversal applies to starting markers.
Important Consideration
Marker orientation is controlled by the SVG marker definition, not directly by the CSS marker-mid property.
Marker Sizing
Marker size is controlled through SVG attributes such as markerWidth, markerHeight, viewBox, and markerUnits.
Scale with Stroke Width
<marker id="scaled-point" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="5" markerHeight="5" markerUnits="strokeWidth">
<circle cx="5" cy="5" r="4" fill="#f97316" />
</marker>
With markerUnits="strokeWidth", the marker dimensions scale according to the stroke width of the referencing SVG element.
User-Space Units
<marker id="fixed-point" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse">
<circle cx="5" cy="5" r="4" fill="#f97316" />
</marker>
The userSpaceOnUse value measures marker dimensions in the current user coordinate system rather than scaling directly with stroke width.
Change the Stroke Width
.marked-path {
stroke-width: 5;
marker-mid: url(#scaled-point);
}
Increasing the stroke width also increases the marker's displayed size when the marker uses stroke-width units.
Important Consideration
The marker-mid property selects the marker graphic. Its dimensions are configured separately in the SVG marker definition.
marker Shorthand
The marker shorthand sets marker-start, marker-mid, and marker-end to the same value.
Shorthand Example
path {
marker: url(#circle-marker);
}
Equivalent Longhand Declarations
path {
marker-start: url(#circle-marker);
marker-mid: url(#circle-marker);
marker-end: url(#circle-marker);
}
Both examples assign the same marker to all applicable positions.
Intermediate Markers Only
path {
marker-start: none;
marker-mid: url(#circle-marker);
marker-end: none;
}
Only intermediate vertices receive markers.
Override the Shorthand
path {
marker: url(#arrow-marker);
marker-mid: url(#circle-marker);
}
The starting and ending positions use arrow markers, while intermediate vertices use circle markers.
Shorthand Reset
path {
marker-mid: url(#circle-marker);
marker: none;
}
The later shorthand resets all three marker positions to none, removing the intermediate markers.
Removing Intermediate Markers
Set marker-mid to none to remove markers from intermediate vertices without changing the starting or ending marker properties.
Remove Intermediate Markers
path {
marker-mid: none;
}
Keep Starting and Ending Markers
path {
marker-start: url(#circle-marker);
marker-mid: none;
marker-end: url(#arrow-marker);
}
The starting and ending markers remain assigned, while intermediate markers are removed.
Remove All Markers
path {
marker: none;
}
Use the shorthand when all marker positions should be cleared.
marker-mid Example
This example demonstrates how marker-mid adds orange circular markers at intermediate vertices of SVG polylines while leaving their starting and ending points unmarked.
HTML Example
<svg class="marker-mid-demo" viewBox="0 0 340 220" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Two blue polylines with orange markers at their intermediate vertices">
<defs>
<marker id="demo-mid-circle" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse">
<circle cx="5" cy="5" r="4" fill="#f97316" />
</marker>
</defs>
<polyline class="demo-polyline" points="25,85 90,25 155,85 220,25 310,85" />
<polyline class="demo-polyline" points="25,185 100,125 175,185 250,125 310,165" />
</svg>
CSS Example
.marker-mid-demo {
display: block;
width: 100%;
max-width: 480px;
height: auto;
}
.marker-mid-demo .demo-polyline {
fill: none;
stroke: #2563eb;
stroke-width: 3;
marker-mid: url(#demo-mid-circle);
}
Each polyline has five vertices. The orange circles appear at the three intermediate vertices of each polyline. The first and last vertices remain unmarked.
Remove the Intermediate Markers
.marker-mid-demo .demo-polyline {
marker-mid: none;
}
Add Markers to Every Vertex
.marker-mid-demo .demo-polyline {
marker: url(#demo-mid-circle);
}
The shorthand adds the same circle marker to the starting, intermediate, and ending vertices.
Add an Ending Arrow
Define an arrow marker inside the SVG <defs> element:
<marker id="demo-end-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#2563eb" />
</marker>
Then apply both marker properties:
.marker-mid-demo .demo-polyline {
marker-mid: url(#demo-mid-circle);
marker-end: url(#demo-end-arrow);
}
The intermediate vertices display orange circles, while the ending vertex displays a blue arrowhead.
Increase the Marker Size
Change the marker definition to use a larger viewport:
<marker id="demo-mid-circle" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="16" markerHeight="16" markerUnits="userSpaceOnUse">
<circle cx="5" cy="5" r="4" fill="#f97316" />
</marker>
The intermediate circles become larger without changing their placement along the polylines.
Common Mistakes
Expecting Markers on a Simple Line
A straight SVG <line> has no intermediate vertices. Use marker-start or marker-end for its endpoints.
Confusing marker-mid with HTML List Markers
The marker-mid property is used for SVG graphics. It does not control list bullets or numbering.
Using an Undefined Marker ID
polyline {
marker-mid: url(#missing-marker);
}
If the referenced marker does not exist or cannot be accessed, the intended graphic will not appear.
Expecting Markers at Equal Intervals
Intermediate markers are placed at vertices between path segments, not at evenly spaced distances along the path.
Confusing Curve Control Points with Vertices
Control points used to shape Bézier curves do not automatically receive intermediate markers.
Ignoring Marker Reference Coordinates
Incorrect refX and refY values can cause markers to appear offset from their intended vertices.
Ignoring Marker Orientation
Directional markers may point unexpectedly if the marker's orient attribute is not configured appropriately.
Overwriting the Property with the Shorthand
path {
marker-mid: url(#circle-marker);
marker: none;
}
The later shorthand removes the intermediate markers.
Expecting the Property to Work on Ordinary HTML Elements
The property applies to supported SVG graphics, not regular HTML boxes or text elements.
Important Considerations
Keep the following points in mind when using marker-mid:
- The property displays SVG markers at intermediate vertices.
- The initial value is
none. - The property is inherited.
- It accepts a marker URL reference or
none. - Markers are defined using the SVG
<marker>element. - The marker definition is commonly placed inside
<defs>. - The marker's
idis used in the CSS URL reference. - Marker placement depends on the SVG shape's geometry.
- Intermediate markers appear between consecutive path segments.
- A simple SVG line has no intermediate marker positions.
- Polylines can have multiple intermediate vertices.
- Closed shapes have additional vertex behavior at their closing point.
- Paths containing multiple subpaths can have intermediate markers within each subpath.
- Markers are not automatically distributed at equal intervals.
- Bézier control points are not automatically marker vertices.
- The
orientattribute controls marker rotation. - The
autovalue aligns markers according to path geometry. - The
refXandrefYattributes control marker alignment. - The
markerWidthandmarkerHeightattributes control marker viewport dimensions. - The
markerUnitsattribute controls how marker dimensions are measured. - Markers can scale with the stroke width of the referencing element.
- The
markershorthand sets all three marker positions. - Later shorthand declarations can override
marker-mid. - Setting
marker-mid: noneremoves intermediate markers. - Use
marker-startfor starting vertices. - Use
marker-endfor ending vertices. - Use the
markershorthand when the same marker is needed at all positions.
Browser Support
The CSS marker-mid property is widely supported in modern browsers for SVG graphics, including Chrome, Edge, Firefox, Safari, and Opera.
Support for external SVG references and certain marker features may vary. Test marker placement, orientation, and sizing in the browsers your project supports.
For current compatibility information, visit Can I Use? and search for SVG markers.
Specifications
The marker-mid property is defined in the SVG 2 specification and the CSS Fill and Stroke Module Level 3 specification.
CSS Fill and Stroke Module Level 3: marker-mid
These specifications describe how intermediate markers are referenced, positioned, and rendered along supported SVG graphics.
For additional documentation and examples, consult MDN Web Docs.
