MYDS Logo

    MYDS

    Beta

    Link

    This component extends the <a> HTML element (or anchor element) and is used to display hyperlinks.

    Usage

    import { Link } from "@govtechmy/myds-react/link";
    export default () => (
      <Link href="/" primary>
        {/* The link's destination should be indicated here. */}
        Malaysia's Official Design System
      </Link>
    );

    Examples

    If you need to use the Link component provided by a different package, you can use the asChild prop and wrap the component. Here's an example using Next.js:

    You can also create a custom component and import it as needed:

    import { Link as LinkPrimitive } from "@govtechmy/myds-react/link";
    import NextLink from "next/link";
     
    export const Link = (props) => (
      <LinkPrimitive asChild>
        <NextLink {...props} />
      </LinkPrimitive>
    );

    Open in a New Tab

    Opens the link in a new tab by setting target="_blank".

    Note

    All current versions of major browsers now automatically use the behaviour of rel="noopener" for any links with target="_blank"

    Primary

    Used to toggle the link text colour.

    Underline

    Controls when the link should have an underline.

    Props

    PropTypeDefault
    asChild
    boolean
    -
    href
    string
    -
    newTab
    boolean
    false
    primary
    boolean
    false
    underline
    enum
    always

    On this page