Ant Design Svelte

Layout

Page structure, sidebar, collapsing and responsive navigation.

When to use

Layout defines the structure of the page: header, content, footer and side navigation. Svelte uses separate LayoutHeader, LayoutContent, LayoutFooter and LayoutSider. Layout can be nested so that the header covers the entire screen or only the area next to the menu.

The component defines the framework, and the application organizes the menu, content and routing. The state of Menu inside Sider is consistent with its folding through the context.

Structure and side panel

Place parts of the page in Layout according to their role. hasSider explicitly specifies a horizontal structure for SSR; For a complex conditional composition, this helps preserve the original layout before registering child sections.

Problem Setting Example
Assemble the page frame Family Layout Basic structures
Place a header above all sections Nested Layout Header above the side menu
Collapse navigation LayoutSider.collapsible, bind:collapsed Rollable panel
Move control button trigger={null}, external handler Own button
Change panel to fit screen width breakpoint Adaptive panel

width sets the normal Sider width, collapsedWidth sets the collapsed width. Collapsed supports bind; defaultCollapsed specifies the initial local state. onCollapse reports the value and reason of clickTrigger/responsive.

trigger=null removes the standard button. With collapsedWidth=0, the panel can disappear completely, leaving a special expand button; zeroWidthTriggerStyle styles it. For an external trigger, keep the name accessible and associated with the collapsed state.

Adaptability and positioning

breakpoint uses the width of the viewport. onBreakpoint reports threshold crossing, and onCollapse receives the reason responsive. This state is different from manually pressing a button; adaptive example shows both events.

hasSider is also recognized for direct Sider via CSS, but an explicit prop is useful for nested or conditional sections. Keep navigation and content area names accessible regardless of panel width.

Panel on top of content is a CSS application composition, not a separate Layout mode. The same applies to pinned cap and pinned menu: customize the position, height, padding of the main content and custom scroll area.

theme=light/dark for Sider sets the design of the side area itself. This is not switching the entire ConfigProvider theme. The Menu inside it uses the Sider context; For a separate Menu outside the panel, its own settings are applied.

Design and DOM

Sections support class/style, rootClassName and bind:nativeElement. Sider additionally has classNames/styles available for root/body by object or function from props; styles contains CSS strings. Sider design shows both areas.

theme.components.Layout is connected to Layout, its sections and Sider. Design tokens set the background, header/footer sizes and paddings, panel colors and trigger. Local class/style and semantic styles specify the design after the theme.

ConfigProvider.layout accepts LayoutConfig with class and style, without semantic slots. Record applies to Layout containers, including nested ones; Header, Content, Footer and Sider do not receive it directly. undefined inherits the parent setting, and its object, including {}, replaces the entire record. The general and local design classes are added together; style is applied after theme variables and before local style.

General settings show inheritance, local padding, resetting record in nested provider and updating indents with saving draft and collapsed. CSS text properties such as color can be inherited by child sections using normal browser rules - it is not assigning a layout-record to those sections.

Layout.prefixCls and LayoutSider.prefixCls are set independently. A non-empty local prop takes precedence over the global ConfigProvider.prefixCls. The empty string and undefined use the provider's base prefix with the suffix layout or layout-sider; without configuration these are ant-layout and ant-layout-sider. The container's root classes and states change, and the Sider's body and trigger also change.

LayoutHeader, LayoutContent and LayoutFooter accept their own prefixCls: this is a full section class, without an automatic suffix. For example, prefixCls="region" gives the class region, not region-header. The empty line inherits the base prefix ConfigProvider with the suffix layout-header/content/footer. A container's local prefix does not change the classes of its sections; common prefixCls applies to the entire family. ConfigProvider.layout still only contains class/style.

Section prefixes show independent and shared classes Header/Content/Footer, returning standard classes and saving draft. Inside Layout, sections inherit its variables, including the owner's style; without Layout they get their own theme values ​​even with SSR. The local style of the section retains priority.

Local prefixes switch without re-creating the DOM, losing draft, highlighting, focus and collapsed. The body and aria-controls identifiers of the button are preserved, the namespace of the --ant-layout-* variables and the ant-layout-css-var marker are not renamed. The direct child Sider is recognized by SSR regardless of the prefix; for a complex composition, still set hasSider explicitly. When collapsedWidth=0, the content becomes inert, and the trigger remains available for expansion.

The header, content and footer retain the native semantics of the corresponding sections. Collapsing changes the available width, so check labels and interactive elements inside the narrow panel. Menu links must retain real href attributes for app navigation.

Examples

Hat
Contents
Basement
Hat
Contents
Basement
Hat
Contents
Basement

Basic structures

Header, content, footer and nested Layout. hasSider explicitly sets the horizontal structure already on the server.

overview

Work area of the selected section.

Project documentation

Header, contents and footer

Horizontal Menu controls the current section of the example. There are no links to external sites inside the card.

Documentation

Work area

The header remains common to the two columns.

Basement

Header above the side menu

The overall cap covers the entire width. A nested Layout separates the navigation and workspace.

Workspace

Contents of the right column.

Basement section

Side menu and section footer

The general header is located above the columns. The nested Layout leaves a footer underneath the right workspace.

Revealed

Roll-up panel

Built-in trigger controls collapsed. Menu inherits the Sider state; labels are returned upon disclosure.

Access to the button is maintained when the panel width is zero.

Own button

trigger=null hides the built-in button. The outer Button changes bind:collapsed and communicates the state via aria-expanded.

The work area remains full width.

Panel on top of content

As in the official example, the overlay is created by the CSS of the application. The width of the work area does not change when the panel is expanded.

Change the width of the window.

From md

Waiting for change

Adaptive panel

breakpoint=md collapses the panel below 768px. Zero width enables a special trigger; callbacks differentiate between responsive and clickTrigger.

Fixed hat

Document section 1

Document section 2

Document section 3

Document section 4

Document section 5

Document section 6

Fixed hat

position:sticky keeps the header at the top edge of its own scroll area. The main menu of the site remains separate.

Section contents 1

Section contents 2

Section contents 3

Section contents 4

Section contents 5

Section contents 6

Sticky side menu

Sider remains inside the scroll container thanks to sticky. The example does not use fixed relative to the site window.

Local design preserves the Layout structure.

Sider design

root and body are available from LayoutSider. The styles function gets collapsed; the design of the remaining sections is specified via class/style.

Workspace
The panel state is maintained when switching.

Workspace

Initial review example: adaptive panel and external control.

Draft
The setting affects the Layout container.
Revealed
Nested empty record resets the class/style of the provider.

General Layout settings

ConfigProvider.layout, local style, reset record and save draft and minimized panel.

Section
Revealed
Standard sections
Standard Layout
Layout: woodger-layout; Sider: woodger-sider

Local CSS prefixes

Independent prefixCls Layout and Sider, standard sections, draft, collapse and adjacent layout.

Inside Layout

Hat
Basement

Without Layout

Hat
The section receives tokens of its ConfigProvider area.
Basement

Inside the Layout, the header inherits 56px from the style container; without it, uses the headerHeight token: 48.

Header: woodger-header; Content: woodger-content; Footer: woodger-footer

Section prefixes

Complete Header/Content/Footer classes, common prefix, inheritance within Layout and tokens of individual sections.

API

Themes of the ant.design live page are mapped to the public API of the installed package. Full definitions of Props are in @woodger/antd.

Topics of official examples
ThemeExample or limitation
Basic StructureNested sections and hasSider.
Header-Content-FooterTop navigation and content.
Header-SiderCommon header above two columns.
Header Sider 2General header and footer of the right work area.
SiderBuilt-in collapse and Menu.
Custom triggerExternal button and trigger=null.
Collapsible overlayComposition with absolute Sider.
Responsivebreakpoint and zero-width trigger.
Fixed HeaderSticky in a local scroll container.
Fixed SiderSticky Sider in its own area.
Component configGeneral class/style, local priorities, record reset and state saving.
Local CSS prefixesIndependent namespace Layout/Sider, native sections, SSR and state saving.
Local section prefixes (Svelte)Own and common classes Header/Content/Footer, inheritance and sections without Layout.

Layout

PropertyDescriptionTypeDefault
prefixClsLocal full CSS prefix of container and states. Does not change sections/Sider; undefined/empty string use the common prefix + layout.stringConfigProvider / ant-layout
hasSiderClear horizontal structure with SSR. The direct child Sider is also recognized with its own prefixCls.booleanautomatically

LayoutSider

LayoutSider Sidebar Options
PropertyDescriptionTypeDefault
prefixClsFull prefix of Sider, body, states and trigger. An empty string inherits the common prefix + layout-sider; ids/aria-controls are saved.stringConfigProvider / ant-layout-sider
collapsedControlled state; supports bind:collapsed.booleanfalse
defaultCollapsedInitial state without external control.booleanfalse
collapsibleBuilt-in collapse button.booleanfalse
widthWidth of the opened panel, number in px.number | string200
collapsedWidthWidth of folded panel; 0 enables special trigger.number | string80
breakpointAutomatic minimizing according to viewport.GridBreakpoint—
themeDesign of Sider and its built-in trigger.light | darkdark
triggerButton content; null hides the button completely.Snippet | string | number | null | falseArrow
reverseArrowChanges the direction of the built-in arrow and the side of the zero-width trigger.booleanfalse
onCollapseCondition and reason: clickTrigger or responsive.(collapsed, type) => void—
onBreakpointCrossing the adaptive threshold.(broken) => void—
zeroWidthTriggerStyleCSS buttons with collapsedWidth=0.string—
classNamesThe root and body classes.LayoutSiderSemanticSlots | function—
stylesCSS lines root/body; the function receives info.props.LayoutSiderSemanticSlots | function—
nativeElementNative ref of each Layout section.HTMLElement—

ConfigProvider.layout

LayoutConfig contains only class and style. The setting applies to Layout containers, including nested ones. undefined inherits record; its own object, including an empty one, replaces it entirely. The local style is applied after the general one; Header/Content/Footer/Sider do not receive the record directly.

PropertyDescriptionTypeDefault
classGeneral class of Layout containers only; is added to the local class and rootClassName.string—
styleContainer CSS string after theme variables and before local style. Not assigned to sections and Sider directly.string—

prefixCls is set independently for Layout, LayoutSider, LayoutHeader, LayoutContent and LayoutFooter. A non-empty local prop takes precedence over a global prop ConfigProvider.prefixCls; undefined/empty string uses its base prefix with the role suffix. The container local prefix does not rename child sections.

LayoutHeader, LayoutContent, LayoutFooter

LayoutSectionProps includes prefixCls, children, class, rootClassName, style, nativeElement and native HTML attributes. LayoutProps additionally contains hasSider.

PropertyDescriptionTypeDefault
prefixClsFull section CSS class without adding a suffix. A non-empty local prop takes precedence over a general prefix; undefined/empty string inherit the base prefix ConfigProvider + layout-header/content/footer.stringConfigProvider / ant-layout-header/content/footer

Semantic DOM

Layout creates a div, LayoutHeader - header, LayoutContent - main, LayoutFooter - footer, LayoutSider - aside with an inner body. The structure is chosen by the application; Layout itself does not create routes or manage the selected Menu item.

Sider has root/body available via classNames/styles. The collapse button is a real button with aria-expanded and aria-controls; expandLabel/collapseLabel set its name. With a zero width, the content becomes inert. For the remaining sections, class, rootClassName, style and bind:nativeElement are available.

Registration tokens

Sixteen current component tokens verified against ant.design. theme.components.Layout applies to sections, sidebar and trigger. class/style and semantic styles Sider specify local styling.

Layout Component Tokens
TokenPurpose
bodyBgWork area background.
footerBgBasement background.
footerPaddingBasement indentations.
headerBgHeader background.
headerColorHeader text.
headerHeightHeader height.
headerPaddingHorizontal header padding.
lightSiderBgLight panel background.
lightTriggerBgLight panel button background.
lightTriggerColorLight panel button text.
siderBgDark panel background.
triggerBgDark panel button background.
triggerColorThe color of her icon.
triggerHeightBuilt-in button height.
zeroTriggerHeightZero panel button height.
zeroTriggerWidthIts width.
Common tokens of the current topic
TokenCurrent value
colorTextrgba(0,0,0,0.88)
fontSize14

FAQ

Why hasSider with SSR?

It explicitly sets the structure before registering the Sider. The direct child of Sider is also recognized via CSS; a complex composition is better described explicitly.

How to associate Menu with collapsing?

Menu inside Sider receives panel context. To control the panel itself, use bind:collapsed; inlineCollapsed is needed for a separate Menu outside the Sider.

Is overlay a separate API mode?

No, this is a CSS composition of the application with a panel on top of the content.

What happens below the breakpoint?

Sider reports onBreakpoint and changes collapsed with reason responsive. When collapsedWidth=0, a special button remains if trigger is not null.

Is it possible to use sections without Layout?

For the page frame you usually need a Layout. In Svelte, the individual LayoutHeader, LayoutContent and LayoutFooter also receive their ConfigProvider area tokens, initial CSS values ​​and border-box before hydration. A nested section inherits the variables of the nearest Layout; the native prefixCls does not reset them.

Does the design of sections with your own prefixCls match the React standard?

Svelte retains the design of the section role, including the general class of the header, content and footer. The erroneous container design of sections found in the React standard Ant Design 6.6.8 with its own prefixCls is not reproduced. The class changes, but the native header/main/footer, their tokens and the state of the controls are preserved.