Visually communicates content is in the process of loading
Skeleton components are intended for use on initial page load to loosely represent a container-based user interface that is not fully loaded. A skeleton should never take the place of static content.
Use skeletons to represent regions or sections of a page, such as search results or a product tile filmstrip, rather than specific interactive elements like a standalone button or image.
Skeletons serve to reduce cumulative layout shift (CLS) and improve user-perceived load times. They should be temporary and not visible for more than a few seconds before being replaced by content.
A complete skeleton requires the CdrSkeleton
wrapping component and at least one CdrSkeletonBone
component.
At its core, CdrSkeleton is essentially a paint brush you can use to create any UI shape your application requires. However, there are several presets to allow quick assembly of basic UI elements. All type options are fluid and will expand to fit their container.
<CdrSkeleton>
<CdrSkeletonBone />
</CdrSkeleton>
<CdrSkeleton>
<CdrSkeletonBone type="heading" />
</CdrSkeleton>
Repeated lines within a skeleton will automatically change their length
<CdrSkeleton>
<CdrSkeletonBone type="line" />
<CdrSkeletonBone type="line" />
<CdrSkeletonBone type="line" />
</CdrSkeleton>
<CdrSkeleton>
<CdrSkeletonBone type="rectangle" />
</CdrSkeleton>
<CdrSkeleton>
<CdrSkeletonBone type="square" />
</CdrSkeleton>
Skeletons use motion in a left to right gradient to convey the UI is still loading and the page is not frozen. This effect can be disabled.
<CdrSkeleton>
<CdrSkeletonBone :motion="false" />
</CdrSkeleton>
aria-busy=true
and aria-live=”polite”
A skeleton should not be visible for more than 5 seconds so a fallback is needed if loading is delayed or fails.
CdrSkeleton is used to provide a visual placeholder while content is loading.
motion
name
Boolean
type
'true'
default
Toggle animation on/off. When `true`, animated gradient will be used while loading. When `false` a static background color will be used.
CdrSkeletonBone is used to provide a visual placeholder for a single line of content while content is loading.
type
name
String
type
'default'
default
Available types are `default`, `heading`, `line`, `rectangle`, and `square`.
Find more information about using Slots in the article Installing Cedar.
default
name
Sets the innerHTML for CdrSkeleton.
A skeleton can be used in conjunction with other Cedar components to construct whatever UI approximation your app requires.
<CdrSkeleton v-if="contentLoading">
<CdrCard class="skeleton-card">
<section>
<CdrSkeletonBone type="rectangle" />
<div class="inset">
<CdrSkeletonBone type="heading" />
<div class="skeleton-card--body">
<CdrSkeletonBone type="line" />
<CdrSkeletonBone type="line" />
<CdrSkeletonBone type="line" />
</div>
</div>
</section>
</CdrSkeleton>
<CdrCard v-else>
<!-- True UI/Content -->
</CdrCard>
CdrSkeleton can be used with Vue's built-in suspense component (opens new window) component to render a fallback for asynchronous components.
<Suspense>
<!-- component with nested async dependencies -->
<MyAsyncComponent />
<!-- loading state via #fallback slot -->
<template #fallback>
<CdrSkeleton>
<CdrSkeletonBone />
</CdrSkeleton>
</template>
</Suspense>