Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document inline stylesheets #3355

Merged
merged 9 commits into from
Jun 6, 2023
24 changes: 24 additions & 0 deletions src/content/docs/en/guides/styling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,30 @@ You can apply global styles to your Markdown content by adding [`<style>` tags](

If you are using Tailwind, the [typography plugin](https://tailwindcss.com/docs/typography-plugin) can be useful for styling Markdown.

## Production

### Bundle control

When Astro builds your site for production deployment it combines your CSS into chunks. Each page on your site is its own chunk, and CSS that is shared between multiple pages are split off into their own chunks.
matthewp marked this conversation as resolved.
Show resolved Hide resolved

In each of your HTML files there will be `<link rel="stylesheet">` tags added for each of the chunks that the pages needs.
matthewp marked this conversation as resolved.
Show resolved Hide resolved

In a site with a large number of pages and many different shared pieces of styles this can some times lead to many requests for styles. Astro has a way to minimize requests through the `inlineStylesheets` option. Using this option Astro will put the (minimized) stylesheet into a `<style>` tag rather than request it externally.
matthewp marked this conversation as resolved.
Show resolved Hide resolved

```js
import { defineConfig } from 'astro/config';

export default defineConfig({
build: {
inlineStylesheets: 'auto'
}
});
```

When using the `'auto'` option Astro will inline stylesheets that are below the `vite.build.assetsInlineLimit` threshold. This is usually a good option as bigger sheets, such as global ones used by all pages, will be fetched externally and cached, while smaller sheets, such as a page's own styles, will be inlined.

You can also set this option to `'always'` which will inline all stylesheets.
matthewp marked this conversation as resolved.
Show resolved Hide resolved

## Advanced

:::caution
Expand Down