logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
YouMindTRACTIANLobeHub
6.4.3
  • Components Overview
  • Changelog
    v6.4.3
  • General
    • Button
    • FloatButton
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
    • 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
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • App
    • BorderBeam
      6.4.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 pageLLMs.md
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
    targetOffsetCustomize scroll offset for this anchor link. It takes precedence over the targetOffset prop of the Anchor componentnumber-6.4.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
    targetOffsetCustomize scroll offset for this anchor link. It takes precedence over the targetOffset prop of the Anchor componentnumber-6.4.0

    Semantic DOM

    Design Token

    Component TokenHow to use?
    Token NameDescriptionTypeDefault Value
    linkPaddingBlockVertical padding of linknumber4
    linkPaddingInlineStartHorizontal padding of linknumber16
    Global TokenHow to use?
    Token NameDescriptionTypeDefault Value
    colorPrimaryBrand color is one of the most direct visual elements to reflect the characteristics and communication of the product. After you have selected the brand color, we will automatically generate a complete color palette and assign it effective design semantics.string#1677ff
    colorSplitUsed as the color of separator, this color is the same as colorBorderSecondary but with transparency.stringrgba(5,5,5,0.06)
    colorTextDefault text color which comply with W3C standards, and this color is also the darkest neutral color.stringrgba(0,0,0,0.88)
    fontFamilyThe font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics.string-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
    fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
    fontSizeLGLarge font sizenumber16
    lineHeightLine height of text.number1.5714285714285714
    lineTypeBorder style of base componentsstringsolid
    lineWidthBorder width of base componentsnumber1
    lineWidthBoldThe default line width of the outline class components, such as Button, Input, Select, etc.number2
    motionDurationSlowMotion speed, slow speed. Used for large element animation interaction.string0.3s
    paddingXXSControl the extra extra small padding of the element.number4

    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
    • itemTitle
      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