Ant Design supports the [last 2 versions of modern browsers](https://browsersl.ist/#q=defaults). If you need to be compatible with legacy browsers, please perform downgrade processing according to actual needs:
If you need to support older browsers, please use [StyleProvider](https://github.com/ant-design/cssinjs#styleprovider) for degradation handling according to your actual requirements.
The CSS-in-JS feature of Ant Design uses the ":where" selector by default to lower the CSS selector specificity, reducing the additional cost of adjusting custom styles when upgrading for users. However, the compatibility of the ":where" syntax is relatively poor in older browsers ([compatibility](https://developer.mozilla.org/en-US/docs/Web/CSS/:where#browser_compatibility)). In certain scenarios, if you need to support older browsers, you can use `@ant-design/cssinjs` to disable the default lowering of specificity (please ensure version consistency with antd).
Note: After turning off the `:where` downgrade, you may need to manually adjust the priority of some styles. Or you can **use PostCSS plugin** to raise application css selector priority. PostCSS provides many plugins can help on this. e.g:
To unify LTR and RTL styles, Ant Design uses CSS logical properties. For example, the original `margin-left` is replaced by `margin-inline-start`, so that it is the starting position spacing under both LTR and RTL. If you need to be compatible with older browsers, you can configure `transformers` through the `StyleProvider` of `@ant-design/cssinjs`:
Ant Design supports configuring `@layer` for unified css priority downgrade since `5.17.0`. After the downgrade, the style of antd will always be lower than the default CSS selector priority, so that users can override the style (please be sure to check the browser compatibility of `@layer`):
```tsx
import { StyleProvider } from '@ant-design/cssinjs';
export default () => (
<StyleProviderlayer>
<MyApp/>
</StyleProvider>
);
```
antd styles will be encapsulated in `@layer` to lower the priority:
In responsive web development, there is a need for a convenient and flexible way to achieve page adaptation and responsive design. The `px2remTransformer` transformer can quickly and accurately convert pixel units in style sheets to rem units relative to the root element (HTML tag), enabling the implementation of adaptive and responsive layouts.
Since `<style />` tag insertion is different from normal DOM in Shadow DOM scenario, you need to use `StyleProvider` of `@ant-design/cssinjs` to configure the `container` property to set the insertion position:
```tsx
import { StyleProvider } from '@ant-design/cssinjs';
In some cases, you may need antd to coexist with other style libraries, such as `Tailwind CSS`, `Emotion`, `styled-components`, etc. Unlike traditional CSS solutions, these third-party libraries are often not easy to override antd styles by increasing CSS selector priority. You can configure `@layer` for antd to lower its CSS selector weight, and arrange `@layer` order to solve style override problems:
### antd config `@layer`
```tsx
import { StyleProvider } from '@ant-design/cssinjs';
export default () => (
<StyleProviderlayer>
<MyApp/>
</StyleProvider>
);
```
### TailwindCSS Arrange `@layer`
In global.css, adjust `@layer` to control the order of style override. Place `tailwind-base` before `antd`:
```less
@layer tailwind-base, antd;
@layer tailwind-base {
@tailwind base;
}
@tailwind components;
@tailwind utilities;
```
### reset.css
If you use antd's `reset.css` style, you need to specify `@layer` for it to prevent the style from overriding antd:
```less
@layer reset, antd;
@import url(reset.css) layer(reset);
```
### With other CSS-in-JS libraries
After configuring `@layer` for antd, you don't need to do any additional configuration for other CSS-in-JS libraries. Your CSS-in-JS can completely override antd styles.
### SSR Scene
When using SSR, styles are often rendered inline in HTML through `<style />`. At this time, please make sure that the styles with the specified `@layer` priority order are loaded before `@layer` is used.
#### ❌ Wrong
```html
<head>
<!-- SSR Injection style -->
<style>
@layer antd {
/** ... */
}
</style>
<!-- css file contains @layer xxx, antd; -->
<linkrel="stylesheet"href="/b9a0m0b9o0o3.css"/>
<!-- or write @layer xxx, antd; in html directly -->
<style>
@layer xxx, antd;
</style>
</head>
```
#### ✅ Correct
```html
<head>
<!-- css file contains @layer xxx, antd; -->
<linkrel="stylesheet"href="/b9a0m0b9o0o3.css"/>
<!-- or write @layer xxx, antd; in html directly -->