2022-10-21 22:47:13 +00:00
---
2023-10-18 10:59:43 +00:00
title: '< ClientOnly > '
description: Render components only in client-side with the < ClientOnly > component.
links:
- label: Source
icon: i-simple-icons-github
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/client-only.ts
size: xs
2022-10-21 22:47:13 +00:00
---
2024-03-18 15:17:20 +00:00
The `<ClientOnly>` component is used for purposely rendering a component only on client side.
::note
The content of the default slot will be tree-shaken out of the server build. (This does mean that any CSS used by components within it may not be inlined when rendering the initial HTML.)
::
2022-10-21 22:47:13 +00:00
## Props
2023-10-18 10:59:43 +00:00
- `placeholderTag` | `fallbackTag` : specify a tag to be rendered server-side.
- `placeholder` | `fallback` : specify a content to be rendered server-side.
2022-10-21 22:47:13 +00:00
```vue
< template >
< div >
< Sidebar / >
2024-03-18 15:17:20 +00:00
<!-- The <Comment> component will only be rendered on client - side -->
2022-10-21 22:47:13 +00:00
< ClientOnly fallback-tag = "span" fallback = "Loading comments..." >
< Comment / >
< / ClientOnly >
< / div >
< / template >
```
## Slots
2024-03-18 15:17:20 +00:00
- `#fallback` : specify a content to be rendered on the server and displayed until `<ClientOnly>` is mounted in the browser.
2022-10-21 22:47:13 +00:00
2024-03-18 15:17:20 +00:00
```vue [pages/example.vue]
2022-10-21 22:47:13 +00:00
< template >
< div >
< Sidebar / >
2024-03-18 15:17:20 +00:00
<!-- This renders the "span" element on the server side -->
< ClientOnly fallbackTag = "span" >
<!-- this component will only be rendered on client side -->
< Comments / >
2022-10-21 22:47:13 +00:00
< template #fallback >
<!-- this will be rendered on server side -->
< p > Loading comments...< / p >
< / template >
< / ClientOnly >
< / div >
< / template >
```