Cookie Banner
Inform users about cookie usage on a website
Use the CookieBanner
component to inform users about cookie usage on a website and collect their consent in compliance with privacy regulations like GDPR and CCPA.
You can create the CookieBanner
component with an optional heading and cookie icon. Omit the showIcon
prop to hide the cookie icon. Inside the component, you can pass any element to create the body of the cookie banner. For the accept and decline buttons, you can pass an object with ButtonProps
, along with a text
and icon
prop to set the text and button icon:
For Astro components, you can use an icon type. Please see the documentation of the Icon
component for available icon types. For Svelte and React components, you can import an SVG string and pass that to the icon
prop.
Position
By default, the CookieBanner
is displayed in the bottom right corner of the page in a fixed position. This behavior can be changed using the position
prop:
The position
prop can be set to:
left
: Displays theCookieBanner
component in the bottom left corner.bottom
: Displays theCookieBanner
component on the bottom of the page with a 100% width.
Variants
The CookieBanner
component can be be used with any valid CardProps
type, meaning you can customize its appearance similar to any regular card:
Behavior
The CookieBanner
component also comes with a functionality that hides the banner when a button is clicked and sets a cookie called cookieBannerResponse
that you can use in your application. It’s value will be either true
or false
, depending on whether the user clicks “Decline” or “Accept”.
The CookieBanner
component is only shown again if this cookie expires, or if the user hasn’t interacted with the cookie banner. You can change this behavior and rename the cookie in the Astro component file. Search for the following value in the component files to replace it:
API
Card
component for the CardProps
type, and consult the documentation of the Button
component for the ButtonProps
type. Prop | Purpose |
---|---|
heading | Sets the title of the cookie banner. |
showIcon | Shows a cookie icon next to the heading. |
position | Sets the position of the cookie banner. |
className | Pass additional CSS classes for the cookie banner. |
acceptButton | Sets the accept button for the cookie banner. |
declineButton | Sets the decline button for the cookie banner. |
Request improvement for this page