0Pricing
CSS Academy · Lesson

CSS Layout API and Scope

Build custom layout algorithms with the CSS Layout API and understand Houdini's scope and limits.

CSS Layout API and Scope is a free CSS Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

CSS Houdini Overview

CSS Houdini is a collection of low-level APIs that expose parts of the CSS rendering engine to JavaScript. It includes: Typed OM, Properties & Values API, Paint API, Layout API, and Animation Worklet. Together they enable custom CSS extensions.

What is the CSS Layout API?

The CSS Layout API allows developers to define custom layout algorithms in JavaScript that can be used as values for the CSS display property. You can create layouts as powerful as Grid or Flexbox.

Layout Worklet Structure

A Layout Worklet implements intrinsicSizes() and layout() methods and registers with registerLayout():

// masonry-layout.js
registerLayout("masonry", class {
  async intrinsicSizes(children, edges, styleMap) {
    // calculate min/max content size
  }

  async layout(children, edges, constraints, styleMap) {
    // place children and return fragment data
  }
});

Using a Custom Layout

Reference the registered layout in CSS:

.masonry-container {
  display: layout(masonry);
}

Layout API Status

The CSS Layout API has limited browser support and is largely experimental (behind flags in Chrome). It is more of a research/future API than a production tool today. Masonry layout specifically may be implemented natively in browsers instead.

@scope At-Rule

@scope is a newer CSS feature (part of the CSS Scoping spec) that limits the reach of CSS rules to a specific DOM subtree without adding classes everywhere.

@scope Syntax

Define a scope root and optionally a scope limit:

@scope (.card) {
  :scope { border-radius: 8px; }
  .title { font-size: 1.25rem; }
  /* These rules only apply inside .card elements */
}

@scope with Limit

The scope limit prevents rules from matching inside nested components:

@scope (.article) to (.advertisement) {
  p { line-height: 1.7; }
  /* applies to p inside .article but not inside .advertisement within .article */
}

:scope Pseudo-class

Within @scope, :scope refers to the scope root element:

@scope (.card) {
  :scope { background: white; }
  :scope:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.15); }
}

@scope Browser Support

@scope is supported in Chrome 118+, Safari 17.4+. Firefox support is coming. Use with @supports for safe deployment.

Houdini's Broader Vision

CSS Houdini's goal is to make the web platform extensible — enabling developers to add features to CSS itself rather than waiting for browser vendors to implement them. The APIs available today (Typed OM, @property, Paint) are the most production-ready parts of this vision.

Quick Check

What does @scope (.card) achieve in CSS?

Recap

CSS Houdini is a set of APIs exposing the rendering engine. The Layout API enables custom display algorithms but is mostly experimental. @scope limits CSS rule reach to specific DOM subtrees — preventing style leakage without strict BEM naming. The most production-ready Houdini features are Typed OM, @property, and the Paint API.

Frequently asked questions

Is the “CSS Layout API and Scope” lesson free?

Yes — the full text of “CSS Layout API and Scope” is free to read here on the web, and the CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO.

What will I learn in “CSS Layout API and Scope”?

Build custom layout algorithms with the CSS Layout API and understand Houdini's scope and limits. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CSS Academy?

No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “CSS Layout API and Scope” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CSS Academy lesson?

Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The CSS Typed Object Model (OM)
  2. CSS Properties and Values API (@property)
  3. CSS Paint API: Worklets
  4. CSS Layout API and Scope
← Back to CSS Academy