Styles and Semantic DOM
Start with theme design tokens for general changes. For a single instance, use class/style and published semantic slots. These methods solve different problems and can be combined.
Connecting CSS
ConfigProvider imports the CSS of the package. Without a provider, connect it once at the entry point:
import '@woodger/antd/styles.css';
React reset.css and Less settings are not part of the public exports @woodger/antd. Connect your own application reset consciously: global rules for button, input, table or svg can change the geometry and accessibility of components.
If the styling is broken, first check the calculated styles and CSS order. Don't start with a global !important for all library elements.
Selecting a design method
| Problem | Method |
|---|---|
| Colors, metrics and uniform application states | theme.token |
| Special design for one family | theme.components |
| Component Defaults in Application Area | ConfigProvider.button and other component config |
| Root Element Class or CSS | class/style |
| Design of published internal parts | classNames/styles |
In Svelte style and semantic styles values are specified by CSS strings. React objects { color: 'red' } are not copied directly. Semantic classNames/styles can accept callbacks with props if supported by the family.
The slots are different: Button has root/icon/content, Form has label/help/extra, Timeline has itemTitle/itemContent. Check the Semantic DOM section of the corresponding page, rather than selecting names from the browser DOM.
Local style and defaults
The example below combines ConfigProvider.button, semantic styles, local style and a custom class. The button next to it shows the setting limit. For Button, the local style is applied after styles.root; The provider and instance classes are added together.
This sequence does not replace the directory of constituent components: item styles, popup slots and internal buttons may have additional levels. ConfigProvider and family pages describe specific priorities.
Design priorities
Provider Defaults, semantic styles, scoped CSS and local style.
<script lang="ts">
import { Button, Checkbox, ConfigProvider } from '@woodger/antd';
let local = $state(true);
let count = $state(0);
</script>
<style>
.example {
display: grid;
gap: 16px;
}
.sample {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.sample :global(.guide-action-content) { font-weight: 700; }
</style>
<div class="example">
<Checkbox bind:checked={local}>{("Local button style")}</Checkbox>
<div class="sample">
<ConfigProvider button={{
class: 'guide-default-action',
style: 'border-radius: 4px',
styles: { root: `
border-width: 2px;
border-style: dashed;
` }
}}>
<Button class="guide-styled-action" classNames={{ content: 'guide-action-content' }}
styles={{ root: 'padding-inline: 20px' }}
style={local ? `
border-radius: 16px;
border-style: solid;
` : undefined}
onclick={() => { count++; }}>{("Save")}</Button>
</ConfigProvider>
<Button onclick={() => { count++; }}>{("Regular button")}</Button>
</div>
<output
aria-label={("Clicks in example styles")}
>{("Presses: ")}{count}</output>
</div>
Scoped CSS Svelte
The parent's Scoped selector does not automatically access the internal markup of the child component. Pass your own semantic class and restrict the global part of the selector to your wrapper:
.sample :global(.guide-action-content) {
font-weight: 700;
}
The sample wrapper must be in this Svelte component. A native class is more stable than a selector with a generated hash or an exact chain of internal div. For your element, read the actual colors via theme.useToken, as in topic guide.
Popup and CSS prefixes
Popup can be located in the body, outside the component wrapper. The .sample :global(...) selector will then not match it. Use supported popup styles/classNames or select a container via getPopupContainer. Svelte context and DOM location are different boundaries; porting to ShadowRoot does not automatically deliver the CSS there.
Callback can be defined without accessing the DOM during SSR:
function popupContainer(trigger?: HTMLElement) {
return trigger?.parentElement ?? document.body;
}
Pass a function, not the result of its call. Check clipping, scroll, stacking context and focus trap of the selected container. The generic getPopupContainer does not apply to all families equally.
Local prefixCls changes the CSS classes of a particular instance. A list of families with a common ConfigProvider.prefixCls is given in provider description; the remaining components still retain local/default classes. A non-empty local prefixCls takes precedence over the general one; an empty string for connected families returns the fallback of the provider. Examples show inheritance, local exceptions, and independent prefixes of child popups.
theme.cssVar.prefix specifies the namespace of theme variables. If namespace is not specified or inherited, the source theme uses the provider's base prefix; changing classes does not guarantee changing the namespace. Priorities are discussed in topics. Steps can use its own prefixCls or inherit a common one.