Skip to content
Client v5: BLE, BLE Hosting, HTTP, Jobs - Linux, MacOS, & Blazor Support! Full AOT, RX on BLE only & MANY other features! Power up!

Barcodes & QR Codes | Blazor Usage

The Blazor components render either an inline <svg> (the default) or a PNG data: URI inside an <img>. Both paths use the same pure-managed encoder as MAUI, so they work identically on Blazor WebAssembly with no JS interop.

@using Shiny.Blazor.Controls.Barcodes
@using Shiny.Controls.Barcodes

ImageFormat selects how the barcode is emitted:

ImageFormatOutputBest for
Svg (default)Inline <svg> with a single <path> and shape-rendering="crispEdges"Almost everything — scales infinitely without aliasing, stays tiny in the DOM, no base64 bloat
Png<img> with a data:image/png;base64,… URIWhen you specifically need a real <img> element (e.g. to drag/save the image, or a downstream tool that expects a bitmap)

Prefer SVG unless you have a concrete reason to need a bitmap.

<!-- SVG (default) — crisp at any CSS size -->
<BarcodeView Value="5901234123457" Format="BarcodeFormat.Ean13" />
<!-- PNG when you need a raw <img> -->
<BarcodeView Value="5901234123457"
Format="BarcodeFormat.Ean13"
ImageFormat="BarcodeImageFormat.Png"
AltText="Product barcode" />
ParameterTypeDefaultDescription
Valuestring?nullContent to encode. null/"" renders nothing
FormatBarcodeFormatCode128Symbology — see Symbologies
ImageFormatBarcodeImageFormatSvgSvg (inline <svg>) or Png (<img> with data URI)
PixelWidthint400Encoder pixel width; also the default CSS width when CssWidth is unset
PixelHeightint150Encoder pixel height; also the default CSS height when CssHeight is unset
MarginPixelsint10Quiet-zone padding
ForegroundColorstring"#000000"CSS hex color
BackgroundColorstring"#FFFFFF"CSS hex color
CssWidthstring?nullCSS width override for the host ("100%", "4cm", …)
CssHeightstring?nullCSS height override for the host
AltTextstring?nullalt attribute, used only when rendered as a PNG <img>
QRErrorCorrectionQRErrorCorrectionMediumHonored only when Format = QRCode

A BarcodeView subclass locked to Format = QRCode that adds a square Size parameter (it overwrites both PixelWidth and PixelHeight). It inherits everything else from BarcodeView, including QRErrorCorrection.

<QRCodeView Value="https://shinylib.net"
Size="300"
QRErrorCorrection="QRErrorCorrection.High" />
ParameterTypeDefaultDescription
Sizeint300Square edge length — overwrites PixelWidth/PixelHeight

PixelWidth/PixelHeight set the encoder resolution; CssWidth/CssHeight set the rendered size of the host element. When the CSS overrides are unset, the host falls back to {PixelWidth}px / {PixelHeight}px.

Because SVG output is vector, you can encode at a modest resolution and still render it at any size:

<!-- Fill the container; SVG stays crisp -->
<BarcodeView Value="@order.Tracking"
Format="BarcodeFormat.Code128"
CssWidth="100%"
CssHeight="80px" />

The host is an inline-block <div> (SVG) or <img> (PNG) with class shiny-barcode, so you can target it from your stylesheet too.

The component re-encodes inside OnParametersSet whenever any parameter changes. That means:

  • Keep Value (and the other parameters) stable across renders — passing a freshly-computed string on every render forces a re-encode each cycle.
  • Like MAUI, invalid input never throws: a failed encode just clears the output (empty SVG / empty src). Validate upstream if you need explicit error feedback.