Troubleshooting SVG Path Creation: Why Can't I Create a Hole?

Abstract: Resolve SVG path holes by drawing inner boundaries counter-clockwise while outer boundaries are clockwise to satisfy the non-zero winding rule.

Created: 2026-10-22 by
You cannot create a hole in an SVG path because the browser renders shapes based on the non-zero winding rule or evenodd fill-rule, which requires proper directionality of subpaths. To fix this, ensure your outer boundary is drawn clockwise and your inner boundary (the hole) is drawn counter-clockwise. Alternatively, use two separate elements with opposite fill-rules to achieve the desired transparent cutout effect.

Understanding the Non-Zero Winding Rule

When you define a complex shape using the d attribute in an SVG <path>, the rendering engine must decide which areas are "inside" the shape and which are "outside." By default, most browsers use the non-zero winding rule. This algorithm works by casting a ray from a point outward to infinity and counting how many times the path crosses that ray. If the crossings cancel each other out, the point is considered outside. For a simple rectangle, this is straightforward. However, when you attempt to create a hole by adding a second loop inside the first, the direction of the drawing matters immensely. If both the outer loop and the inner loop are drawn in the same direction, the winding numbers do not subtract correctly. The result is that the entire area, including the intended hole, is filled. This is why users often find that their "hole" disappears and becomes just another filled section of the design. To visualize this, imagine walking along the path. If you walk around the outer edge clockwise and then walk around the inner edge also clockwise, the computer sees two positive windings. It does not see a subtraction. To create a void, you need one positive winding and one negative winding. This is where the concept of path direction becomes critical for troubleshooting.

The Solution: Opposite Path Directions

The most reliable way to create a hole within a single <path> element is to reverse the direction of the subpath that defines the hole. In SVG path data, commands like M (move to), L (line to), and C (cubic bezier) define the geometry. The order of these commands determines the direction. For example, consider a square with a circular hole in the center. You would start with the outer square. Draw it in a clockwise direction. Then, move to the top-left of the circle. Instead of continuing clockwise, draw the circle in a counter-clockwise direction. You can achieve this by reversing the sequence of points or by changing the sign of the coordinates if you are generating the path programmatically. Here is a conceptual example of how the data should look:
<path d="
  M 10,10 
  L 90,10 
  L 90,90 
  L 10,90 
  Z 
  M 50,30 
  A 20,20 0 1,0 50,70 
  A 20,20 0 1,0 50,30 
"/>
In this snippet, the outer square is defined first. The inner circle uses arc commands (A). Notice the flags in the arc command. The third flag indicates sweep-flag. Setting it to 1 draws clockwise, while 0 draws counter-clockwise. By ensuring the inner loop has the opposite sweep flag or reversed coordinate sequence, you signal to the renderer that this area should be excluded from the fill. If you are using a vector graphics editor like Adobe Illustrator or Inkscape, these tools usually handle this automatically when you use the "subtract" or "exclude" operations. They generate the path data with the correct opposing directions behind the scenes. If you are hand-coding, you must manually verify this directionality.

Alternative Approach: Using Two Separate Paths

Sometimes, managing direction within a single complex path can become error-prone, especially if the shape is highly irregular. A simpler alternative is to use two separate <path> elements. You can draw the main shape as usual. Then, draw the hole as a separate path that covers the same area but uses the fill-rule="evenodd" attribute on the container or individual paths. The evenodd rule is more forgiving than the non-zero rule. It simply counts whether a ray crosses an odd or even number of path segments. If it crosses once, it's inside. If twice, it's outside. This means you don't strictly need to worry about clockwise vs. counter-clockwise directions for both loops. As long as both the outer and inner boundaries are closed, the evenodd rule will treat the area between them as empty space. This approach is particularly useful when dealing with multiple holes. Each hole can be its own subpath or separate path, and the evenodd rule ensures they all behave consistently without requiring strict directional control. However, note that some older renderers or specific CSS filters might behave differently with evenodd, so testing across browsers is recommended.

Common Pitfalls in Path Data

Even with correct directions, several issues can prevent holes from appearing. First, check for unclosed paths. If your inner loop does not end with a Z command or return to its starting point, the rendering engine may not recognize it as a distinct boundary. Always ensure every subpath is closed. Second, overlapping lines can cause visual artifacts. If your inner path intersects with the outer path incorrectly, it might create unintended fills. Use the fill-rule attribute explicitly to avoid ambiguity. For instance, adding fill-rule="nonzero" or fill-rule="evenodd" to your <path> tag makes your intent clear to the browser. Third, if you are generating SVGs via JavaScript, ensure that floating-point precision errors do not cause the paths to miss their endpoints slightly. Even a tiny gap can break the winding calculation. Rounding your coordinates to two decimal places can often resolve these subtle glitches. Finally, remember that strokes are handled separately from fills. A hole in the fill does not necessarily mean a hole in the stroke. If you want the border of the hole to disappear as well, you must ensure the path structure supports it, or use masks and clip-paths for more complex transparency effects.

Frequently Asked Questions

Why does my hole appear filled when I use the same direction for both loops?

Because the non-zero winding rule adds up the winding numbers, two loops in the same direction result in a net winding number of two, which is still considered "inside." Reversing the direction of the inner loop creates a net winding of zero, marking it as outside.

Can I use masks instead of path directions to create holes?

Yes, using an SVG <mask> element is a powerful alternative. You define a white shape for the visible area and a black shape for the hole. This method ignores winding rules entirely and relies on alpha channel transparency, making it ideal for complex designs with many cutouts.

What is the difference between nonzero and evenodd fill rules?

The nonzero rule considers direction, adding or subtracting windings based on clockwise or counter-clockwise movement. The evenodd rule ignores direction and simply counts the total number of crossings; an odd count means inside, and an even count means outside.

How do I debug path direction in Chrome DevTools?

You can inspect the SVG element in the Elements tab. Look at the computed styles for fill-rule. While you cannot directly see the winding direction visually, you can temporarily change the fill color to red and add a stroke to trace the path. Animate the path or use console logs to print the d attribute values to verify the sequence of commands.

Do I need to close the inner path with Z?

Yes, it is best practice to close the inner path with a Z command. While some browsers might infer closure, explicit closure ensures consistent behavior across all SVG renderers and prevents unexpected gaps or overlaps in the final image.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More