CSS & Styling
Este conteúdo não está disponível em sua língua ainda.
You can style your Starlight site with custom CSS files or use the Starlight Tailwind plugin.
Custom CSS styles
Customize the styles applied to your Starlight site by providing additional CSS files to modify or extend Starlight’s default styles.
-
Add a CSS file to your
src/
directory. For example, you could set a wider default column width and larger text size for page titles: -
Add the path to your CSS file to Starlight’s
customCss
array inastro.config.mjs
:
You can see all the CSS custom properties used by Starlight that you can set to customize your site in the props.css
file on GitHub.
Tailwind CSS
Tailwind CSS support in Astro projects is provided by the Astro Tailwind integration. Starlight provides a complementary Tailwind plugin to help configure Tailwind for compatibility with Starlight’s styles.
The Starlight Tailwind plugin applies the following configuration:
- Configures Tailwind’s
dark:
variants to work with Starlight’s dark mode. - Uses Tailwind theme colors and fonts in Starlight’s UI.
- Disables Tailwind’s Preflight reset styles while selectively restoring essential parts of Preflight required for Tailwind’s border utility classes.
Create a new project with Tailwind
Start a new Starlight project with Tailwind CSS pre-configured using create astro
:
Add Tailwind to an existing project
If you already have a Starlight site and want to add Tailwind CSS, follow these steps.
-
Add Astro’s Tailwind integration:
-
Install the Starlight Tailwind plugin:
-
Create a CSS file for Tailwind’s base styles, for example at
src/tailwind.css
: -
Update your Astro config file to use your Tailwind base styles and disable the default base styles:
-
Add the Starlight Tailwind plugin to
tailwind.config.mjs
:
Styling Starlight with Tailwind
Starlight will use values from your Tailwind theme config in its UI.
If set, the following options will override Starlight’s default styles:
colors.accent
— used for links and current item highlightingcolors.gray
— used for background colors and bordersfontFamily.sans
— used for UI and content textfontFamily.mono
— used for code examples
Theming
Starlight’s color theme can be controlled by overriding its default custom properties. These variables are used throughout the UI with a range of gray shades used for text and background colors and an accent color used for links and to highlight current items in navigation.
Color theme editor
Use the sliders below to modify Starlight’s accent and gray color palettes. The dark and light preview areas will show the resulting colors, and the whole page will also update to preview your changes.
When you’re happy with your changes, copy the CSS or Tailwind code below and use it in your project.
Dark mode
Body text is displayed in a gray shade with a high contrast with the background. Links are colored. Some text, like the table of contents, has a lower contrast. Inline code has a distinct background.
Light mode
Body text is displayed in a gray shade with a high contrast with the background. Links are colored. Some text, like the table of contents, has a lower contrast. Inline code has a distinct background.
Add the following CSS to your project in a custom CSS file to apply this theme to your site.
The example Tailwind config file below
includes generated accent
and gray
color palettes to use in the
theme.extend.colors
configuration object.