Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Wiring it up

Call initConsent once before the first render, render the banner once near the root, and give visitors a way back in.

App bootstrap
Before the first render: this catalogue does exactly this, once, in its layout.
Show code
<head>
  <app-analytics-head gtm-id="GTM-XXXX" clarity-id="abcd1234" cookie-domain=".example.com" />
</head>

<app-consent-banner policy-href="/cookie-policy" />
A page without the shared theme
For a site on its own CSS: the banner renders sealed in its own shadow root with its own styles, and the tag adds the small banner-only script itself. Nothing else from this library needs to load. Brand it with the theme's custom properties.
Show code
<style>:root { --color-primary: rebeccapurple; }</style>

<app-consent-banner standalone="true" policy-href="/cookie-policy" />

Categories

List only the optional categories the site sets cookies for. Essential always shows, and a category left out is never granted.

Only the categories the site uses
List the optional categories the site really sets cookies for. Essential always shows. A category left out has no row, saves as off, and Accept all never grants it. The saved choice keeps the same shape.
Show code
<app-consent-banner categories="@(new[] { ConsentCategory.Analytics, ConsentCategory.Marketing })" policy-href="/cookie-policy" />
All three categories
Show code
<app-consent-banner policy-href="/cookie-policy" />

Reopening the banner

Withdrawing consent must be as easy as giving it, so one attribute on any link reopens the banner.

Cookie settings link
Any element carrying data-consent-settings reopens the banner in settings mode. The listener is document-wide, so it reopens every banner instance mounted on the page: in a real app that is exactly one.
Show code
<a href="#" data-consent-settings>Cookie settings</a>

Every option

Every value of every prop, one cell each.

title

title="How we use cookies"

description

description="We use cookies to measure visits and campaigns."

policy-href

policy-href="/cookie-policy"

policy-label

policy-label="Privacy notice"

analytics-description

analytics-description="Measures how visitors use the site."

functional-description

functional-description="Remembers the choices you make."

marketing-description

marketing-description="Measures how well our campaigns work."

categories

categories="analytics functional marketing" (default)
categories="analytics"
categories="functional"
categories="marketing"

position

position="bottom-left" (default)
position="bottom-right"
position="bar"

standalone

standalone="false" (default)
standalone="true"

preview

preview="true": draws open and saves nothing

class

class: extra classes on the element, no visible change here

Guidance

What to do, and what to avoid.

Use it when

  • Any product surface that sets non-essential cookies (analytics, ads, feature personalization).
  • You want one shared consent record across the website and its subdomains.

Reach for something else when

  • You need to announce something to every visitor, not ask a compliance question. → AppBanner
  • You are building the Razor head include that loads the tags and the consent record (the app-analytics-head tag).
  • You are starting analytics or tags by hand beside the banner. The choice saved through initConsent decides which analytics start: the analytics category turns PostHog capture and Clarity on, and Consent Mode holds Tag Manager's tags until analytics consent, or marketing consent when adStorage is on.

Reference

Try every prop, read the full list, and check keyboard and screen reader behaviour.

all three analytics functional analytics marketing analytics
bottom-left bottom-right bar
React, generated from the controls
<AppConsentBanner
/>
Razor, the same props
<app-consent-banner />

12 props. The 5 most used come first.

Used on most screens 5 props

PropTypeDefaultDescription
positiondefault bottom-left bottom-left | bottom-right | bar bottom-left The corner it pins to, or the full-width bar. bar is a slim full-width bar along the bottom at every width.
titledefault Cookies on this site string Cookies on this site Title, and the dialog's accessible name.
descriptiondefault - string - The explanation above the buttons.
policy-hrefdefault - string - Link to the cookie policy; no link when omitted.
categoriesdefault analytics functional marketing string analytics functional marketing The optional categories to show, separated by spaces, from analytics, functional and marketing. Essential always shows and is not listed. A category left out has no row, saves as off and is never granted by Accept all. An unknown name throws.

Less common 7 props

PropTypeDefaultDescription
policy-labeldefault Cookie policy string Cookie policy The policy link's text.
analytics-descriptiondefault - string - What the analytics category covers.
functional-descriptiondefault - string - What the functional category covers.
marketing-descriptiondefault - string - What the marketing category covers.
previewdefault false bool false Draw the banner open without reading or saving consent, for a design surface that never ran initConsent. Nothing is stored.
standalonedefault false bool false Render sealed in a shadow root with bundled styles, for a page that does not load @webority/theme.
classdefault - string - Extra classes on the element; passes through as a plain HTML attribute.

Method on the element, called from your own script (the <app-analytics-head> include already does this for you): open({ settings, focus }), close(). Event: wui-consent-save with detail = { analytics, functional, marketing }.

Screen reader

3 notes
  • The panel is a dialog named by its title.
  • There is no close button by design, so the only way out is a choice: Accept all, Reject all, or Save preferences in settings mode.
  • Escape does not dismiss it, for the same reason as the missing close button.