Cookie Banner
A customizable cookie consent banner that handles privacy compliance with zero configuration required.
The Cookie Banner component provides an elegant way to obtain and manage consent from your users. It handles all the complexity of privacy regulations while providing a smooth user experience that integrates naturally with your application.
Usage
The Cookie Banner uses a compound component pattern, giving you complete control over its structure when needed. Think of it like building blocks – you can use the pre-assembled version, or arrange the pieces yourself for custom layouts.
import { ConsentManagerProvider, CookieBanner } from "@c15t/react";
export default function App() {
return (
<ConsentManagerProvider options={{
mode: 'c15t',
backendURL: 'https://your-instance.c15t.dev',
consentCategories: ['necessary', 'marketing'],
}}>
<CookieBanner />
</ConsentManagerProvider>
);
};
Styling
The Cookie Banner is designed to adapt to your application's visual style. Learn more about our styling system.
Theme Variables
These keys are available on the theme object to customize your banner.
Scroll Locking
The Cookie Banner supports scroll locking, a technique that prevents users from interacting with your website until they've made a cookie consent choice.
<CookieBanner lockScroll={true} />
When enabled, scroll locking:
- Prevents page scrolling and interaction
- Displays a background overlay
- Ensures users must make a privacy choice before accessing content
For best results, use scroll locking together with focus trapping to ensure complete keyboard accessibility.
Info
For detailed implementation guides, best practices, and compliance considerations, see our Scroll Locking Guide.
Accessibility
The Cookie Banner is built with accessibility in mind:
- Proper ARIA roles and labels (role="dialog", aria-modal="true")
- Keyboard navigation and interaction support
- Focus management and trapping
- Screen reader announcements
- Semantic HTML structure
These features work automatically, ensuring all users can interact with your privacy controls effectively.
Focus Trapping
The Cookie Banner implements focus trapping when it's displayed, which is an essential accessibility feature that prevents keyboard focus from moving outside the banner. This behavior:
- Ensures users complete the consent flow before interacting with other page elements
- Prevents accidental interaction with content that shouldn't be accessible yet
- Helps compliance with accessibility guidelines like WCAG 2.4.3 (Focus Order)
Info
Focus trapping is enabled by default and recommended for accessibility compliance. For more details on implementation and best practices, see our useFocusTrap hook documentation.
Best Practices
Follow these guidelines for optimal implementation:
- Place the banner at the root level of your application
- Keep the title and description clear and concise
- Use the pre-assembled version unless you need custom layouts
- Test the banner across different screen sizes
- Ensure your theme maintains sufficient contrast ratios
- Consider scroll locking for strict compliance scenarios
- Test with keyboard navigation to ensure accessibility
API Reference
CookieBanner
The main component accepts these props: