How to Add Margins to QR Codes

Scaling a QR code correctly is a vital step in balancing visual impact with technical readability in brand advertising. To achieve this, using margins (often called "quiet zones") improves QR code readability and ensures that scanning devices recognize the code correctly within unique layouts. Specific adjustments to width, height, and overall scale directly influence the final output ratio and visual presentation.

This guide demonstrates how to use margins to effectively resize and frame your QR code with IronQR, ensuring a perfect fit for any professional layout.

Adding Margins to QR Code

Establishing a proper quiet zone can be achieved by configuring the Margins property within the QrStyleOptions class. This property accepts a single integer that defines a uniform blank border around all four sides of the QR code.

In this example, we define a style configuration with a margin of 40 pixels, apply these settings to the QR code during the rendering process, and then save the resulting image as a PNG file.

:path=/static-assets/qr/content-code-examples/how-to/add-margins-qr-code.cs
using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions
{
    // Set all margins to 40px
    Margins = 40,

};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap using the style options
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qr-uniform-margins.png");
$vbLabelText   $csharpLabel

Output

Quiet Zone QR Code

Adding Margins to Specific Sides

For asymmetrical layouts, use the MarginTop, MarginBottom, MarginLeft, and MarginRight properties within QrStyleOptions. This provides precise control over each side of the quiet zone independently.

In this example, custom values are defined for each margin alongside specific dimensions and a background color.

:path=/static-assets/qr/content-code-examples/how-to/add-specific-margins-qr-code.cs
using IronQr;
using IronSoftware.Drawing;

// Configure QR code styling with individual margins and background color
QrStyleOptions combinedOptions = new QrStyleOptions
{
    Dimensions = 400,
    MarginTop = 50,
    MarginBottom = 50,
    MarginLeft = 20,
    MarginRight = 20,
    BackgroundColor = IronSoftware.Drawing.Color.LightYellow,
};

string url = "https://ironsoftware.com/";

// Generate QR code from URL
QrCode qrCombined = QrWriter.Write(url);

// Apply styling options and export as bitmap
AnyBitmap qrCombinedImage = qrCombined.Save(combinedOptions);

// Save QR code to file
qrCombinedImage.SaveAs("qr-custom-margins.png");
$vbLabelText   $csharpLabel

Output

As you can see, the vertical margins are visibly larger than horizontal sides.

Selective Margin Spacing

Generated QR Codes with Added Margins

Quiet Zone QR Code
Selective Margin Spacing
Ahmad Sohail
Full Stack Developer

Ahmad is a full-stack developer with a strong foundation in C#, Python, and web technologies. He has a deep interest in building scalable software solutions and enjoys exploring how design and functionality meet in real-world applications.

Before joining the Iron Software team, Ahmad worked on automation projects ...

Read More
Ready to Get Started?
Nuget Downloads 54,926 | Version: 2025.12 just released