Add Margins to QR Code
using IronQr;
using IronSoftware.Drawing;

// 1. Uniform Margin Approach
var uniformOptions = new QrStyleOptions
{
    Margins = 40
};

// 2. Specific Margin Approach
var customOptions = new QrStyleOptions
{
    MarginTop = 30,
    MarginBottom = 30,
    MarginLeft = 10,
    MarginRight = 10,
};

// Set target URL and generate QR code
string url = "https://ironsoftware.com/";
QrCode qr = QrWriter.Write(url);

// Save both versions for adding margins
qr.Save(uniformOptions).SaveAs("qr-uniform-margins.png");
qr.Save(customOptions).SaveAs("qr-custom-margins.png");
NuGet Download
PM > Install-Package IronQR
Add Margins to QR Code

Add Margins to QR Code

Adding a margin, or "quiet zone," around a QR code is essential for ensuring scannability and professional design integration. Proper spacing allows scanning devices to easily isolate the code from surrounding text, images, or branding elements, preventing read errors. By adjusting margins, you can create a clean visual buffer that maintains the integrity of the QR code regardless of where it is placed in your layout.

5-step guide for adding margins to a QR code

  • using IronQr;
  • using IronSoftware.Drawing;
  • string url = "https://ironsoftware.com/";
  • QrStyleOptions marginOptions = new QrStyleOptions { Margins = 40 };
  • qr.Save(marginOptions/).SaveAs("qr-margins.png");

Code Explanation

First, we define the layout using the QrStyleOptions class. Setting the Margins property applies a uniform "quiet zone" to all four sides of the code simultaneously, which is the most efficient way to ensure general scannability.

For more granular control, we use specific properties such as MarginTop, MarginBottom, MarginLeft, and MarginRight. This is particularly useful when the QR code needs to be aligned to a specific corner of a document or if the design requires asymmetrical padding. Finally, the styling is applied during the Save process, rendering the QR code bitmap with the exact pixel dimensions specified in your options.

Explore How to Add Margins to QR Codes with IronQR.

Ready to Get Started?

Nuget Downloads 80,612Version:2026.11just released