CSS shape-rendering Property
The CSS shape-rendering property provides rendering hints that help browsers choose how to draw the edges of SVG shapes.
It allows developers to express a preference for rendering speed, crisp edges, or geometric precision. The property primarily affects SVG shapes such as rectangles, circles, paths, polygons, and lines. These values are hints rather than guarantees, so their visual effects can vary between browsers and display devices.
shape-rendering Syntax
The shape-rendering property accepts one of four predefined keywords or a CSS-wide keyword.
Basic Syntax
selector {
shape-rendering: crispEdges;
}
Available Values
.svg-shape {
shape-rendering: auto;
}
.svg-shape {
shape-rendering: optimizeSpeed;
}
.svg-shape {
shape-rendering: crispEdges;
}
.svg-shape {
shape-rendering: geometricPrecision;
}
CSS-Wide Keywords
.svg-shape {
shape-rendering: initial;
}
.svg-shape {
shape-rendering: inherit;
}
.svg-shape {
shape-rendering: unset;
}
.svg-shape {
shape-rendering: revert;
}
.svg-shape {
shape-rendering: revert-layer;
}
The property uses a single keyword. It does not accept numeric values, lengths, percentages, or multiple rendering hints.
Property Values
| Value | Description |
|---|---|
auto |
Allows the browser to balance rendering speed, edge quality, and geometric precision. |
optimizeSpeed |
Suggests prioritizing rendering speed over geometric precision and edge quality. |
crispEdges |
Suggests emphasizing sharp edges, potentially by disabling antialiasing. |
geometricPrecision |
Suggests prioritizing accurate geometric rendering over speed. |
initial |
Resets the property to auto. |
inherit |
Uses the computed value from the parent element. |
unset |
Uses the inherited value because the property is inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | Yes |
| Applies to | SVG shapes |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Related properties | fill, stroke, stroke-width, vector-effect |
| Specification | SVG 2 |
Valid Values
svg rect {
shape-rendering: crispEdges;
}
svg circle {
shape-rendering: geometricPrecision;
}
svg path {
shape-rendering: optimizeSpeed;
}
svg polygon {
shape-rendering: auto;
}
Invalid Values
svg rect {
shape-rendering: sharp;
}
svg circle {
shape-rendering: smooth;
}
svg path {
shape-rendering: 1;
}
svg polygon {
shape-rendering: crispEdges geometricPrecision;
}
Only the defined rendering keywords and CSS-wide keywords are valid. Keywords are case-sensitive in their standard spelling when used as CSS identifiers.
How It Works
SVG shapes are rendered from vector geometry. When their edges do not align exactly with device pixels, the browser may use antialiasing to smooth their appearance.
The shape-rendering property gives the browser a preference for how to handle this rendering process.
Step 1: Create an SVG Shape
<svg viewBox="0 0 200 100" aria-hidden="true">
<rect x="10" y="10" width="180" height="80" fill="#2563eb"/>
</svg>
Step 2: Apply a Rendering Hint
svg rect {
shape-rendering: crispEdges;
}
The browser receives a preference for sharp edges when rendering the rectangle.
Step 3: Compare Rendering Modes
.fast-shape {
shape-rendering: optimizeSpeed;
}
.crisp-shape {
shape-rendering: crispEdges;
}
.precise-shape {
shape-rendering: geometricPrecision;
}
Each value expresses a different rendering priority. Browsers may produce similar results when their rendering engines already optimize the shape effectively.
Rendering Hints Are Not Guarantees
The specification does not require every browser to use a particular antialiasing algorithm. The browser decides how to interpret each hint.
Inheritance
svg {
shape-rendering: geometricPrecision;
}
Because the property is inherited, SVG shapes inside the element can use the same rendering preference unless they override it.
auto
The auto value allows the browser to choose an appropriate balance between rendering speed, edge appearance, and geometric accuracy.
svg path {
shape-rendering: auto;
}
When to Use auto
Use auto when the browser's default SVG rendering produces acceptable results. It is generally the best starting point for ordinary SVG illustrations and icons.
Default Behavior
Because auto is the initial value, explicitly declaring it is unnecessary unless overriding an inherited rendering hint.
svg {
shape-rendering: crispEdges;
}
svg .smooth-shape {
shape-rendering: auto;
}
The second rule allows the selected shape to use automatic rendering rather than inheriting the parent's crisp-edge preference.
optimizeSpeed
The optimizeSpeed value suggests that the browser prioritize rendering performance over edge quality and geometric precision.
svg path {
shape-rendering: optimizeSpeed;
}
Potential Rendering Behavior
A browser may simplify rendering operations or reduce antialiasing work when honoring this hint.
Possible Use Cases
- SVG graphics containing many shapes.
- Frequently updated SVG visualizations.
- Animated SVG scenes where rendering performance is important.
Example
.animated-svg path {
shape-rendering: optimizeSpeed;
}
Important Consideration
The value does not guarantee a measurable performance improvement. Test actual rendering performance before relying on it as an optimization.
crispEdges
The crispEdges value suggests prioritizing sharp edges over smooth antialiasing.
svg rect {
shape-rendering: crispEdges;
}
How It Affects Edges
A browser may disable antialiasing for some or all edges. This can produce sharper boundaries but may also make diagonal lines and curves appear jagged.
Useful Applications
- Rectangular SVG charts.
- Grid lines and geometric diagrams.
- SVG artwork that benefits from hard edges.
Example: Rectangular Bars
.bar-chart rect {
shape-rendering: crispEdges;
}
Important Consideration
The value does not automatically align shapes to the device pixel grid. Fractional coordinates, transforms, and display scaling can still affect the result.
For circles and curved paths, crispEdges may create a visibly rougher appearance than auto or geometricPrecision.
geometricPrecision
The geometricPrecision value suggests prioritizing accurate geometric rendering over speed.
svg circle {
shape-rendering: geometricPrecision;
}
How It Works
The browser is encouraged to preserve geometric accuracy when drawing curves, paths, and other vector shapes.
Useful Applications
- Detailed SVG illustrations.
- Curved icons and logos.
- Diagrams where accurate shape boundaries matter.
- SVG artwork with complex paths.
Example: Curved Path
.illustration path {
shape-rendering: geometricPrecision;
}
Important Consideration
The browser may already render the shape with high precision when using auto. Consequently, switching to geometricPrecision may not produce an obvious visual difference.
SVG Elements
The shape-rendering property is intended for SVG shapes and can be inherited through SVG containers.
Rectangle
svg rect {
shape-rendering: crispEdges;
}
Circle
svg circle {
shape-rendering: geometricPrecision;
}
Ellipse
svg ellipse {
shape-rendering: geometricPrecision;
}
Line
svg line {
shape-rendering: crispEdges;
}
Polyline
svg polyline {
shape-rendering: geometricPrecision;
}
Polygon
svg polygon {
shape-rendering: crispEdges;
}
Path
svg path {
shape-rendering: geometricPrecision;
}
SVG Group
svg .diagram-group {
shape-rendering: crispEdges;
}
Shapes inside the group inherit the rendering hint unless they specify their own value.
HTML Elements
The property is not intended to control ordinary HTML box rendering, text antialiasing, or raster image scaling.
For raster images, the related image-rendering property serves a different purpose.
CSS Property vs. SVG Attribute
SVG supports shape-rendering as both a CSS property and a presentation attribute.
SVG Presentation Attribute
<svg viewBox="0 0 200 100" aria-hidden="true">
<rect x="10" y="10" width="180" height="80" fill="#2563eb" shape-rendering="crispEdges"/>
</svg>
The rendering hint is declared directly on the SVG element.
CSS Property
<svg class="diagram" viewBox="0 0 200 100" aria-hidden="true">
<rect x="10" y="10" width="180" height="80" fill="#2563eb"/>
</svg>
.diagram rect {
shape-rendering: crispEdges;
}
The rendering hint is controlled through a stylesheet.
CSS Cascade
SVG presentation attributes participate in the CSS cascade with lower priority than ordinary author CSS declarations.
Example: CSS Override
<svg class="diagram" viewBox="0 0 200 100" aria-hidden="true">
<rect x="10" y="10" width="180" height="80" shape-rendering="crispEdges"/>
</svg>
.diagram rect {
shape-rendering: geometricPrecision;
}
The stylesheet declaration overrides the presentation attribute.
Important Consideration
Use presentation attributes for self-contained SVG markup or CSS rules when multiple SVG elements need consistent styling.
Practical Examples
Crisp SVG Chart Bars
.chart-bars rect {
shape-rendering: crispEdges;
}
Requests sharper edges for rectangular chart elements.
Precise Curved Illustration
.illustration path {
shape-rendering: geometricPrecision;
}
Requests accurate rendering of complex SVG paths.
SVG Grid Lines
.grid-lines line {
shape-rendering: crispEdges;
}
Suggests hard edges for SVG grid lines.
Performance-Oriented SVG
.animated-diagram {
shape-rendering: optimizeSpeed;
}
Applies a speed-oriented rendering preference to descendant shapes.
Different Hints in One SVG
.diagram .grid {
shape-rendering: crispEdges;
}
.diagram .curves {
shape-rendering: geometricPrecision;
}
Uses different rendering priorities for straight-edged and curved shapes.
Default Rendering
.icon path {
shape-rendering: auto;
}
Allows the browser to select its normal rendering strategy.
Inherited Rendering Hint
.svg-artwork {
shape-rendering: geometricPrecision;
}
Descendant SVG shapes inherit the specified preference.
Resetting a Specific Shape
.svg-artwork .default-shape {
shape-rendering: auto;
}
Overrides an inherited rendering hint for a selected shape.
shape-rendering Example
This example compares the four rendering hints using identical SVG shapes. Differences may be subtle or absent depending on the browser, zoom level, and display resolution.
HTML Example
<div class="shape-rendering-demo">
<div class="render-panel">
<h3>auto</h3>
<svg viewBox="0 0 180 120" role="img" aria-label="SVG shapes with automatic rendering">
<rect x="10.5" y="10.5" width="65" height="65" fill="#2563eb"/>
<circle cx="125.5" cy="43.5" r="32.5" fill="#0d9488"/>
<path d="M 10 105 L 90 80 L 170 105" fill="none" stroke="#dc2626" stroke-width="3"/>
</svg>
</div>
<div class="render-panel speed">
<h3>optimizeSpeed</h3>
<svg viewBox="0 0 180 120" role="img" aria-label="SVG shapes with speed-oriented rendering">
<rect x="10.5" y="10.5" width="65" height="65" fill="#2563eb"/>
<circle cx="125.5" cy="43.5" r="32.5" fill="#0d9488"/>
<path d="M 10 105 L 90 80 L 170 105" fill="none" stroke="#dc2626" stroke-width="3"/>
</svg>
</div>
<div class="render-panel crisp">
<h3>crispEdges</h3>
<svg viewBox="0 0 180 120" role="img" aria-label="SVG shapes with crisp-edge rendering">
<rect x="10.5" y="10.5" width="65" height="65" fill="#2563eb"/>
<circle cx="125.5" cy="43.5" r="32.5" fill="#0d9488"/>
<path d="M 10 105 L 90 80 L 170 105" fill="none" stroke="#dc2626" stroke-width="3"/>
</svg>
</div>
<div class="render-panel precise">
<h3>geometricPrecision</h3>
<svg viewBox="0 0 180 120" role="img" aria-label="SVG shapes with geometric precision rendering">
<rect x="10.5" y="10.5" width="65" height="65" fill="#2563eb"/>
<circle cx="125.5" cy="43.5" r="32.5" fill="#0d9488"/>
<path d="M 10 105 L 90 80 L 170 105" fill="none" stroke="#dc2626" stroke-width="3"/>
</svg>
</div>
</div>
CSS Example
.shape-rendering-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
gap: 15px;
}
.shape-rendering-demo .render-panel {
padding: 15px;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
}
.shape-rendering-demo h3 {
margin-top: 0;
font-size: 1rem;
}
.shape-rendering-demo svg {
display: block;
width: 100%;
height: auto;
shape-rendering: auto;
}
.shape-rendering-demo .speed svg {
shape-rendering: optimizeSpeed;
}
.shape-rendering-demo .crisp svg {
shape-rendering: crispEdges;
}
.shape-rendering-demo .precise svg {
shape-rendering: geometricPrecision;
}
auto
optimizeSpeed
crispEdges
geometricPrecision
The shapes are identical in all four panels. Only the rendering hint changes. The most noticeable differences, when present, may appear around diagonal edges, curved boundaries, and fractional pixel positions.
Comparing the Values
| Value | Rendering Preference |
|---|---|
auto |
Browser-selected balance |
optimizeSpeed |
Rendering performance |
crispEdges |
Sharp edge appearance |
geometricPrecision |
Geometric accuracy |
Changing the Rendering Hint
.shape-rendering-demo svg {
shape-rendering: crispEdges;
}
Applies the crisp-edge preference to all four SVG examples, unless a more specific rule overrides it.
Restoring Automatic Rendering
.shape-rendering-demo svg {
shape-rendering: auto;
}
Returns the SVG elements to the browser's default rendering preference.
Accessibility Considerations
Rendering hints can affect the visual clarity of SVG graphics, but they do not change their semantic meaning or accessibility information.
Maintain Clear Shape Boundaries
Choose rendering values that keep important lines and boundaries recognizable.
Avoid Jagged Critical Graphics
The crispEdges value may create jagged curves or diagonal lines. Test whether this reduces readability.
Preserve Adequate Contrast
Rendering hints do not replace appropriate contrast between SVG shapes and their backgrounds.
Provide Accessible Names
Informative SVG graphics should have an accessible name or equivalent text description.
<svg viewBox="0 0 100 100" role="img" aria-label="Blue circular indicator">
<circle cx="50" cy="50" r="40" fill="#2563eb"/>
</svg>
Decorative SVG Graphics
Purely decorative SVG graphics can use aria-hidden="true" to avoid unnecessary announcements.
Test Zoom and Scaling
Verify that important SVG details remain recognizable at different zoom levels and display resolutions.
Avoid Depending on Subtle Rendering Differences
Do not use changes in antialiasing or edge sharpness as the only way to communicate important information.
Common Mistakes
Using Unsupported Keywords
svg path {
shape-rendering: smooth;
}
The keyword smooth is not valid. Use one of the four defined rendering values.
Expecting Guaranteed Results
The values are rendering hints. Browsers are not required to produce identical output.
Using the Property for HTML Text
The property does not control ordinary HTML text antialiasing. SVG text has separate rendering considerations.
Confusing shape-rendering With image-rendering
The image-rendering property controls image scaling preferences, while shape-rendering concerns SVG shape rendering.
Expecting crispEdges to Align Pixels
The property does not automatically adjust SVG coordinates to align with device pixels.
Using crispEdges on Every Shape
Sharp-edge rendering may make curved shapes appear jagged.
Assuming optimizeSpeed Improves Performance
Performance improvements depend on the browser and the SVG content. Measure results before relying on this hint.
Ignoring Inheritance
The property is inherited. A declaration on an SVG container can affect many descendant shapes.
Using Multiple Rendering Keywords
svg rect {
shape-rendering: crispEdges geometricPrecision;
}
The property accepts only one rendering keyword.
Expecting Geometry Changes
The property does not modify path coordinates, dimensions, transforms, or stroke widths.
Important Considerations
Keep the following points in mind when using shape-rendering:
- It provides rendering hints for SVG shapes.
- The initial value is
auto. - The property is inherited.
- It accepts four predefined rendering keywords.
autoallows the browser to balance rendering priorities.optimizeSpeedprioritizes rendering speed.crispEdgesprioritizes sharp edges.geometricPrecisionprioritizes geometric accuracy.- The values are hints rather than strict rendering requirements.
- Browser rendering engines may interpret the hints differently.
- Visible differences may depend on display resolution and zoom level.
- The property does not change SVG geometry.
- It does not automatically align coordinates to device pixels.
- It can be applied through CSS or SVG presentation attributes.
- Ordinary CSS declarations can override SVG presentation attributes.
- Declarations on SVG containers can be inherited by descendant shapes.
- It is distinct from
image-renderingandtext-rendering. - Performance improvements should be measured rather than assumed.
- Test important graphics across browsers and display sizes.
Browser Support
The CSS shape-rendering property is widely supported for SVG graphics in modern browsers, including Chrome, Edge, Firefox, and Safari.
Although browsers recognize the property, the visual effect of individual rendering hints can vary. Some values may produce little or no visible difference in certain browsers.
For current compatibility information, visit Can I Use? and search for shape-rendering.
Feature Detection
@supports (shape-rendering: crispEdges) {
svg .grid-lines {
shape-rendering: crispEdges;
}
}
Feature queries can determine whether a browser recognizes the property value, but they cannot confirm how the rendering hint will be implemented visually.
Fallback Behavior
When a browser does not support the property, it ignores the declaration and uses its normal SVG rendering behavior.
Testing Recommendations
Compare shapes with fractional coordinates, curves, diagonal lines, and different stroke widths. Test at multiple zoom levels and on different display devices.
Specifications
The shape-rendering property is defined in the SVG 2 specification.
SVG 2 - shape-rendering Property
The specification describes the rendering hints and how they express preferences for speed, crisp edges, and geometric precision.
For additional documentation and examples, consult MDN Web Docs.
