CSS chapters

Chapter 14 of 17

Modules and Packages

Try this in our CSS Compiler →

Splitting code into files

As your project grows, putting everything in one file becomes a nightmare. CSS lets you split code across many files (called modules) and import names from one file into another. Each module groups together a related set of functions and types.

```css
/* shared.css */
.btn { padding: 0.5rem 1rem; }

/* page.css */ @import url("shared.css"); .btn { background: tomato; } ```

Third-party packages

You almost never need to write everything from scratch. CSS has a huge ecosystem of open-source libraries — for parsing JSON, talking to databases, building web servers, doing maths, and thousands of other tasks. Use the official package manager to add and update dependencies.

Keeping dependencies under control

Each dependency you add is code written by strangers running inside your program. Read what a package actually does before you install it, prefer well-maintained projects with many users, and remove dependencies you no longer use.

Try it yourself

CSS Compiler
Output
Code runs in a sandboxed preview inside your browser — your code is saved locally for next time.