IRONSOFTWAREHOME
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");
Imports IronQr
Imports IronSoftware.Drawing

' 1. Uniform Margin Approach
Dim uniformOptions = New QrStyleOptions With {
    .Margins = 40
}

' 2. Specific Margin Approach
Dim customOptions = New QrStyleOptions With {
    .MarginTop = 30,
    .MarginBottom = 30,
    .MarginLeft = 10,
    .MarginRight = 10
}

' Set target URL and generate QR code
Dim url As String = "https://ironsoftware.com/"
Dim qr As QrCode = 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 74,386Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required