Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,42 @@ const App = () => {
};
```

## Content Security Policy (CSP)

react-hot-toast supports strict Content Security Policies through an opt-in strict CSP mode.

### Default Mode

By default, react-hot-toast uses inline styles for maximum flexibility. This requires `style-src 'unsafe-inline'` in your CSP.

### Strict CSP Mode

For applications with strict CSP that disallow inline styles, enable strict CSP mode:

```jsx
import toast, { Toaster } from 'react-hot-toast';

<Toaster strictCSP={true} />
```

In strict CSP mode:
- All inline `style` props are ignored
- Styling must be done via CSS classes and CSS variables
- Toast positioning uses CSS flexbox instead of inline transforms
- Fully compatible with CSP `style-src 'nonce-...'` directives

The library uses [goober](https://github.com/cristianbote/goober) for styling. To support CSP nonces, set `window.__nonce__` before your app loads:

```html
<script nonce="your-nonce-here">
window.__nonce__ = 'your-nonce-here';
</script>
```

goober will automatically apply the nonce to its generated `<style>` elements.

Make sure your CSP includes `style-src 'nonce-your-nonce-here'` and `script-src 'nonce-your-nonce-here'`.

## Documentation

Find the full API reference on [official documentation](https://react-hot-toast.com/docs).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"dependencies": {
"csstype": "^3.1.3",
"goober": "^2.1.16"
"goober": "^2.1.18"
},
"peerDependencies": {
"react": ">=16",
Expand Down
36 changes: 29 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions site/pages/docs/styling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,55 @@ import { Toaster, ToastBar } from 'react-hot-toast';
)}
</Toaster>;
```

## Strict CSP Mode

For applications with strict Content Security Policies that disallow inline styles, enable `strictCSP` mode:

```jsx
<Toaster strictCSP={true} />
```

In strict CSP mode:
- All inline `style` props are ignored
- Styling must be done via CSS classes and CSS variables
- Toast positioning uses CSS flexbox instead of inline transforms
- The library is fully compatible with CSP `style-src 'nonce-...'` directives

### CSP Nonce Support

The library uses [goober](https://github.com/cristianbote/goober) for styling. To support CSP nonces, set `window.__nonce__` before your app loads:

```html
<script nonce="your-nonce-here">
window.__nonce__ = 'your-nonce-here';
</script>
```

goober will automatically apply the nonce to its generated `<style>` elements.

Make sure your CSP includes `style-src 'nonce-your-nonce-here'` and `script-src 'nonce-your-nonce-here'`.

### Styling with CSS Variables (Strict CSP)

When using strict CSP mode, use CSS variables for theming:

```css
:root {
/* Success toasts */
--rht-success-bg: #ecfdf5;
--rht-success-fg: #065f46;

/* Error toasts */
--rht-error-bg: #fef2f2;
--rht-error-fg: #991b1b;

/* Loading toasts */
--rht-loading-bg: #eff6ff;
--rht-loading-fg: #1e40af;

/* Blank toasts */
--rht-blank-bg: #fff;
--rht-blank-fg: #363636;
}
```
Loading