Astro - Skeleton

  1. get started
  2. installation
  3. astro

Astro

Install and configure Skeleton for Astro.

WARNING: The following guide will install a pre-release version of Skeleton v3. Be aware that some features may be missing, incomplete, or non-functional at this time. Please report bugs and issues on GitHub or Discord.

Learn how to install the Skeleton core into your Astro project. We’ll cover using components in the section below.

1

Create a Project

Start by creating a new Astro project. We recommend selecting all default options.

Terminal window
npm create astro@latest my-skeleton-app
cd my-skeleton-app
2

Install Tailwind

Install Tailwind using Astro Add:

Terminal window
npx astro add tailwind
3

Install Skeleton

Install the Skeleton core package for the Tailwind plugin. Once again, please note this does not include components.

Terminal window
npm i -D @skeletonlabs/skeleton@next
4

Configure Tailwind

Open tailwind.config in the root of your project and make the following changes:

tailwind.config
import { skeleton } from '@skeletonlabs/skeleton/plugin';
import * as themes from '@skeletonlabs/skeleton/themes';
/** @type {import('tailwindcss').Config} */
export default {
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
theme: {
extend: {},
},
plugins: [
skeleton({
// NOTE: each theme included will increase the size of your CSS bundle
themes: [themes.cerberus, themes.rose],
}),
],
};
5

Remove Default Content and Styles

We recommend you open /src/components/welcome.astro and remove all default HTML and CSS. Here’s a simple starter layout.

---
const framework = 'Astro';
---
<main class="p-10 space-y-4">
<h1 class="h1">Hello {framework}</h1>
<p>This page is working.</p>
<button type="button" class="btn preset-filled">Example Button</button>
</main>
6

Set Active Theme

Open /src/layouts/Layout.astro, then set the data-theme attribute on the body tag to define the active theme.

layouts/Layout.astro
<body data-theme="cerberus">...</body>

Run the Project

Start the dev server using the following command.

Terminal window
npm run dev

Using Components in Astro

While Astro can support multiple Frontend frameworks, please be aware this comes with some notable restrictions:

  • With the exception of this experimental flag for React children, components cannot utilize slotted content in .astro files.
  • You will need to install additional packages for both Astro and Skeleton per your framework of choice.
  • You may need a wrapper component to use to utilize all component feature. We’ll demo this below.
1
2

Skeleton Framework Packages

Install only the Skeleton framework(s) packages you intend to use.

Terminal window
@skeletonlabs/skeleton-react@next
Terminal window
@skeletonlabs/skeleton-svelte@next
3

Configure Tailwind

Open tailwind.config in the root of your project and make these changes. First, include the contentPath import.

import { skeleton, contentPath } from '@skeletonlabs/skeleton';

Then append content for ONLY the framework(s) you intend to use.

export default {
{/* ... */}
content: [
'./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}', // <-- Keep this
contentPath(import.meta.url, 'react'), // <-- Add this for React
contentPath(import.meta.url, 'svelte') // <-- Add this for Svelte
],
{/* ... */}
};
4

Using Wrapper Components

In most cases, frontend framework components may not be fully functional if used directly within .astro files. To overcome this, you may utilize a wrapper component of that framework. Here’s a demo using the Skeleton Avatar component as an example.

React

ReactAvatarWrapper.tsx
import React from 'react';
import { Avatar } from '@skeletonlabs/skeleton-react';
export const ReactAvatarWrapper: React.FC = () => {
const imgSrc = '...';
return <Avatar src={imgSrc} name="skeleton" />;
};
page.astro
---
import { ReactAvatarWrapper } from '@components/ReactAvatarWrapper';
---
<ReactAvatarWrapper />

Svelte

SvelteAvatarWrapper.svelte
<script lang="ts">
import { Avatar } from '@skeletonlabs/skeleton-svelte';
const imgSrc = '...';
</script>
<Avatar src={imgSrc} name="skeleton" />
page.astro
---
import { SvelteAvatarWrapper } from '@components/SvelteAvatarWrapper';
---
<SvelteAvatarWrapper />

Run the Project

Start the dev server using the following command.

Terminal window
npm run dev