You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Link` component represents the HTML `<a>` element.
18
-
It accepts the same props as the [`Typography`](/joy-ui/react-typography/) component, as well as the system props.
17
+
The Joy UI Link component replaces the native HTML `<a>` element, and accepts the same props as the [Typography](/joy-ui/react-typography/) component, as well as MUI System props.
After [installation](/joy-ui/getting-started/installation/), you can start building with this component using the following basic elements:
21
+
## Basics
25
22
26
23
```jsx
27
24
importLinkfrom'@mui/joy/Link';
28
-
29
-
exportdefaultfunctionMyApp() {
30
-
return<Link>Hello world!</Link>;
31
-
}
32
25
```
33
26
27
+
The Joy UI Link behaves similar to the native HTML `<a>`, so it renders with an underline by default and has no background color on hover.
28
+
29
+
The demo below shows the two basic states available to the Link: default and disabled.
30
+
Don't forget to always assign an `href` value:
31
+
32
+
{{"demo": "BasicsLink.js"}}
33
+
34
+
## Customization
35
+
36
+
### Variants
37
+
38
+
The Link component supports Joy UI's four global variants: `plain` (default), `soft`, `outlined`, and `solid`.
39
+
40
+
:::warning
41
+
Although the component is technically set to `plain` by default, it will actually render without any variant if you don't customize it.
42
+
This is so that it adheres to the standard visual design of links on the web (no background color on hover).
43
+
:::
44
+
45
+
{{"demo": "LinkVariants.js"}}
46
+
47
+
:::info
48
+
To learn how to add your own variants, check out [Themed components—Extend variants](/joy-ui/customization/themed-components/#extend-variants).
49
+
Note that you lose the global variants when you add custom variants.
50
+
:::
51
+
52
+
### Levels
53
+
54
+
The Link component comes with all the Typography levels to choose from.
55
+
56
+
{{"demo": "LinkLevels.js"}}
57
+
58
+
### Colors
59
+
60
+
Every palette included in the theme is available via the `color` prop.
61
+
Play around combining different colors with different variants.
62
+
63
+
{{"demo": "LinkColors.js"}}
64
+
65
+
### Underline
66
+
67
+
Use the `underline` prop to control how the underline behaves on the Link component.
68
+
It comes with three values: `hover`, `always`, and `none`.
69
+
70
+
{{"demo": "LinkUnderline.js"}}
71
+
72
+
### Disabled
73
+
74
+
Use the `disabled` prop to disable interaction and focus:
75
+
76
+
{{"demo": "LinkDisabled.js"}}
77
+
78
+
### Overlay prop
79
+
80
+
Use the `overlay` prop to make an entire component clickable as a link.
81
+
The demo below shows how to use that with the Card component, ensuring proper accessibility.
82
+
83
+
{{"demo": "LinkCard.js"}}
84
+
34
85
### As a button
35
86
36
-
To use the `Link` as a button, assign the `button` value to the `component` prop.
37
-
It's useful doing it in two main situations:
87
+
To use the Link component as a button, assign the `button` value to the `component` prop.
88
+
This can be useful in two situations:
38
89
39
90
1. The link doesn't have a meaningful href.
40
-
2. The design looks more a link rather than a button.
91
+
2. The design looks more like a button than a link.
41
92
42
93
```js
43
94
<Link
@@ -50,41 +101,16 @@ It's useful doing it in two main situations:
50
101
</Link>
51
102
```
52
103
53
-
### With a typography
104
+
### Usage with Typography
54
105
55
-
`Link`can be used as a child of the [`Typography`](/joy-ui/react-typography/) component.
56
-
In that case, the link component will inherit the typographic level scale from its typography parent, unless a value for the `level` prop is specified.
106
+
The Link component can be used as a child of the [Typography](/joy-ui/react-typography/) component.
107
+
In this situation, the Link will inherit the typographic level scale from its Typography parent, unless you specify a value for the `level` prop on the Link itself.
57
108
58
109
{{"demo": "LinkAndTypography.js"}}
59
110
60
-
### With a card
61
-
62
-
Using the `Link` component as a card title, with the `overlay` prop, ensures proper accessibility when the whole card is clickable.
63
-
64
-
{{"demo": "LinkCard.js"}}
65
-
66
-
## Security
67
-
68
-
When using `target="_blank"` with links, it's [recommended](https://developers.google.com/web/tools/lighthouse/audits/noopener) to always set `rel="noopener"` or `rel="noreferrer"` when linking to a third-party content.
69
-
70
-
-`rel="noopener"` prevents the new page from being able to access the `window.opener` property and ensures it runs in a separate process.
71
-
Without this, the target page can potentially redirect your page to a malicious URL.
72
-
-`rel="noreferrer"` has the same effect, but also prevents the _Referer_ header from being sent to a new page.
73
-
⚠️ Removing the referrer header will affect analytics.
74
-
75
-
## Accessibility
76
-
77
-
Here are a few tips for ensuring an accessible link component, based on [WAI-ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/link/).
78
-
79
-
-**Copywriting**: Avoid generic words as call to action, such as "click here" or "go to".
80
-
Instead, use [descriptive texts](https://developers.google.com/web/tools/lighthouse/audits/descriptive-link-text).
81
-
-**Design:** For a good user experience, links should stand out from the text on the page.
82
-
Keeping the default `underline="always"` behavior is a safe bet.
83
-
-**Href:** If a link doesn't have a meaningful href, [it should be rendered using a `<button>` element](#as-button).
84
-
85
111
## Third-party routing library
86
112
87
-
Here's how you can use the link component with libraries that also provide their version of it.
113
+
The sections below explain how to integrate the Link component with third-party tools that have their own comparable component.
88
114
89
115
### Next.js
90
116
@@ -112,8 +138,27 @@ import Link from '@mui/joy/Link';
112
138
</Link>;
113
139
```
114
140
141
+
## Security
142
+
143
+
When using `target="_blank"` with links to pages on another site, the [Google Chrome Developers documentation](https://developers.google.com/web/tools/lighthouse/audits/noopener) recommends adding `rel="noopener"` or `rel="noreferrer"` to avoid potential security issues.
144
+
145
+
-`rel="noopener"` prevents the new page from being able to access the `window.opener` property and ensures it runs in a separate process.
146
+
Without this, the target page can potentially redirect your page to a malicious URL.
147
+
-`rel="noreferrer"` has the same effect, but also prevents the _Referer_ header from being sent to a new page.
148
+
Note that removing the referrer header will affect analytics.
149
+
150
+
## Accessibility
151
+
152
+
Here are a few tips for ensuring an accessible link component, based on [WAI-ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/link/).
153
+
154
+
-**Copywriting:** Avoid generic words as calls to action, such as "click here" or "go to".
155
+
Instead, use [descriptive text](https://developers.google.com/web/tools/lighthouse/audits/descriptive-link-text) to inform the user about what they'll find when they click the link.
156
+
-**Design:** For a good user experience, links should stand out from the text on the page.
157
+
Keeping the default `underline="always"` behavior is a safe bet.
158
+
-**Href:** If a link doesn't have a meaningful href, [it should be rendered using a `<button>` element](#as-button).
159
+
115
160
## Common examples
116
161
117
-
Examples showcasing how to compose designs with the `Link` component and others as decorators.
162
+
Examples showcasing how to compose designs with the Link component and others as decorators.
0 commit comments