logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
6.0.0-alpha.3
  • Components Overview
  • Changelog
    v6.0.0-alpha.3
  • General
    • Button
    • FloatButton
      5.0.0
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
      5.10.0
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
      5.21.0
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
      5.5.0
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
      DEPRECATED
    • Popover
    • QRCode
      5.1.0
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
      5.0.0
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
      5.1.0
  • Other
    • Affix
    • App
      5.1.0
    • ConfigProvider
    • Util
When To Use
Examples
Basic
Horizontal Anchor
Static Anchor
Customize the onClick event
Customize the anchor highlight
Set Anchor scroll offset
Listening for anchor link change
Replace href in history
Custom semantic dom styling
API
Anchor Props
AnchorItem
Link Props
Semantic DOM
Design Token
FAQ
In version 5.25.0+, the :target pseudo-class of the destination element does not take effect as expected after anchor navigation.

Anchor

Hyperlinks to scroll on one page.
Importimport { Anchor } from "antd";
GitHub
components/anchorIssueOpen issues
Docs
Edit this page
contributors
SplitterBreadcrumb

Resources

Ant Design X
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
X
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
WeaveFox logoWeaveFox-AI Development with WeaveFox 🦊
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

For displaying anchor hyperlinks on page and jumping between them.

Notes for developers

After version 4.24.0, we rewrite Anchor use FC, Some methods of obtaining ref and calling internal instance methods will invalid.

Examples

API

Common props ref:Common props

Anchor Props

PropertyDescriptionTypeDefaultVersion
affixFixed mode of Anchorboolean | Omit<AffixProps, 'offsetTop' | 'target' | 'children'>trueobject: 5.19.0
boundsBounding distance of anchor areanumber5
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
getContainerScrolling container() => HTMLElement() => window
getCurrentAnchorCustomize the anchor highlight(activeLink: string) => string-
offsetTopPixels to offset from top when calculating position of scrollnumber0
showInkInFixedWhether show ink-square when affix={false}booleanfalse
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
targetOffsetAnchor scroll offset, default as offsetTop, examplenumber-
onChangeListening for anchor link change(currentActiveLink: string) => void
onClickSet the handler to handle click event(e: MouseEvent, link: object) => void-
itemsData configuration option content, support nesting through children{ key, href, title, target, children }[] see-5.1.0
directionSet Anchor directionvertical | horizontalvertical5.2.0
replaceReplace items' href in browser history instead of pushing itbooleanfalse5.7.0

AnchorItem

PropertyDescriptionTypeDefaultVersion
keyThe unique identifier of the Anchor Linkstring | number-
hrefThe target of hyperlinkstring
targetSpecifies where to display the linked URLstring
titleThe content of hyperlinkReactNode
childrenNested Anchor Link, Attention: This attribute does not support horizontal orientationAnchorItem[]-
replaceReplace item href in browser history instead of pushing itbooleanfalse5.7.0

Link Props

We recommend using the items form instead.

PropertyDescriptionTypeDefaultVersion
hrefThe target of hyperlinkstring
targetSpecifies where to display the linked URLstring
titleThe content of hyperlinkReactNode

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
linkPaddingBlockVertical padding of linknumber4
linkPaddingInlineStartHorizontal padding of linknumber16
Global TokenHow to use?

FAQ

In version 5.25.0+, the :target pseudo-class of the destination element does not take effect as expected after anchor navigation.

For the purpose of page performance optimization, the implementation of anchor navigation has been changed from window.location.href to window.history.pushState/replaceState. Since pushState/replaceState does not trigger a page reload, the browser will not automatically update the matching state of the :target pseudo-class. To resolve this issue, you can manually construct the full URL: href = window.location.origin + window.location.pathname + '#xxx'.

Related issues: #53143 #54255

Basic

The simplest usage.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Horizontal Anchor

Horizontally aligned anchors

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Set Anchor scroll offset

Anchor target scroll to screen center.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Replace href in history

Replace path in browser history, so back button returns to previous page instead of previous anchor item.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom semantic dom styling

You can customize the semantic dom style of Anchor by passing objects/functions through classNames and styles.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
6.0.0
Static Anchor

Do not change state when page is scrolling.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Customize the onClick event

Clicking on an anchor does not record history.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Customize the anchor highlight

Customize the anchor highlight.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Listening for anchor link change

Listening for anchor link change.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Basic demo
Static demo
API
Anchor Props
Link Props
Basic demo
Static demo
API
Anchor Props
Link Props
Basic demo
Static demo
API
Anchor Props
Link Props
Basic demo
Static demo
API
Anchor Props
Link Props
API
Anchor Props
Link Props
Basic demo
Static demo
  • root
    6.0.0
    Root element with layout positioning, padding, margin, background color and other basic styles
  • item
    6.0.0
    Link item element with padding, text color, hover states, transition animations and other styles
  • title
    6.0.0
    Title text element with font styles, color changes, text decoration, transition effects and other styles
  • indicator
    6.0.0
    Indicator element with width, height, background color, position changes, transition animations and other styles