Skip to content

About

📦 Optimized CSS-to-Inline utility for static site generation and faster rendering. Easy to use and ready to solve your css problems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Astro inline css

divider

  📦 SETUP • ⚙️ CONFIGURATION • ️️️🛰️ FEATURES

divider



                   

divider

About

High-performance CSS-to-Inline utility optimized for Static Site Generation. Eliminate render-blocking stylesheets by automatically inlining critical CSS. Designed for speed, it ensures faster First Contentful Paint (FCP)

divider

Table of content


divider

Requirements

  • node >= 22.17.0
  • bun >= 1.1.0

divider

Installation

Bun

bun i -D astro-inline-css

Npm

npm i -D astro-inline-css

Pnpm

pnpm i -D astro-inline-css

Yarn

yarn i -D astro-inline-css

divider

Usage

In your astro.config.ts file add the following code in integrations:

  import { defineConfig } from 'astro/config';
  import { inlineCss } from 'astro-inline-css'; 

  export default defineConfig({
    integrations: [ inlineCss() ]
  });

divider

Configuration

Extra settings that can be added.

  import { defineConfig } from 'astro/config';
  import { inlineCss } from 'astro-inline-css'; 

  export default defineConfig({
    integrations: [ 
      inlineCss({
        // prefix path for css, example http://localhost/style.css
        prefixPath?: '',

        // Keep font inline
        inlineFonts?: true,

        // Show logs
        logLevel?: 'silent' | 'error' | 'warn' | 'info',

        // Delete source from css file
        pruneSource?: true,

        // If you use CSP in your web this allow you to generete a hash for the inline css
        csp: true,

        // This allow yo te replace in both html and css the generated hash
        cspHashPlaceholder: 'sha256-INLINE_CSS_HASH'
      }) 
    ]
  });

In case you are using csp in astro this is a good configuration example.

  import { defineConfig } from 'astro/config';
  import { inlineCss } from 'astro-inline-css'; 

  export default defineConfig({
    integrations: [ 
      inlineCss({
        csp: true,
        cspHashPlaceholder: 'sha256-INLINE_CSS_HASH'
      }) 
    ],
    security: {
      csp: {
        styleDirective: {
          hashes: ['sha256-INLINE_CSS_HASH']
        }
      }
    },
  });

divider

  BACK TO TOP

divider

  Copyright © All rights reserved
  developed by LuisdaByte and

About

📦 Optimized CSS-to-Inline utility for static site generation and faster rendering. Easy to use and ready to solve your css problems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages