The Native-Syntax Grid Engine.
Rowscolumns is a two-dimensional, recursive, mathematical layout engine that lets you build complex CSS Grids using pure JavaScript syntax directly in your HTML or components.
Traditional grids require nested wrappers for every row and column. Rowscolumns uses Grid Line Placement. You define the geometry, and the engine places your elements onto a flat DOM.
The Old Way:
<div class="row">
<div class="col-4">Sidebar</div>
<div class="col-8">
<div class="row">
<div>Top</div>
<div>Bottom</div>
</div>
</div>
</div>The Rowscolumns Way (Flat HTML and 2D):
<div layout="Grid.col(30, (70).row(50, 50))">
<div>Sidebar</div>
<div>Top Content</div>
<div>Bottom Content</div>
</div>You no longer need separate layout-sm or layout-md attributes for every small change. You can pass responsive objects directly into the methods.
<!-- One line, fully responsive -->
<div layout="Grid.col({ sm: 1, md: 2, lg: 4 })">
<!-- Column weight changes automatically based on screen width -->
</div>Hiding elements usually leaves "ghost" gaps in CSS Grid. The 'none' keyword:
- Hides the element (
display: none). - Collapses the space (removes the grid track).
- Everything else slides over to fill the gap perfectly.
<!-- Hide the middle item on mobile, show on desktop -->
<div layout="Grid.col(1, { sm: 'none', lg: 'auto' }, 1)"> ... </div>Legacy .spread() is replaced by .span(). It is now the single tool for expanding items across multiple tracks.
- Weights:
Grid.col(1, 2)(1/3rd and 2/3rds). - Fractions:
Grid.col(1/3, 2/3). - CSS Units:
Grid.col('200px', 'auto', 1). - Variables:
Grid.col(lg, sm)(Golden ratio: 61.8% and 38.2%).
Start with a number (like 100 or Grid) and chain .col() or .row().
Grid.col(50, (50).row(1, 1)) // Split 50/50, then split the right half into two rows.| Method | Description |
|---|---|
.props({}) |
Styles for the Container (e.g., { gap: '10px' }). |
.childProps({}, [idx]) |
Styles for specific Children (1-based index). |
.offset([idx]) |
Skips a slot to create a "Ghost" space. |
.span({ right: 1 }, [idx]) |
Spans a child across extra tracks (top, right, bottom, left). |
This demonstrates Inline Breakpoints, Responsive Hiding, and Offsets all in one layout:
<div layout="
Grid.col(
{ sm: 1, md: 2, lg: 4 },
(10).col('auto', { sm: 'none', lg: 'auto' }, 1, 'auto'),
{ sm: 1, md: 2, lg: 4 }
)
.offset([1, 4, 6])
.props({ gap: '5px' })
">
<img src="logo.svg" />
<h4>Heading</h4>
<button>Button</button>
</div>For the full API reference, advanced examples, and detailed guides, visit the official documentation:
π rowscolumns.github.io/docs.html
<script type="module">
import { Engine } from 'https://unpkg.com/rowscolumns/dist/index.mjs';
Engine.init();
</script>
<div layout="Grid.col(50, 50)"> ... </div>npm install rowscolumnsReact:
import { Layout, Grid } from 'rowscolumns/react';
import 'rowscolumns'; // Activates syntax extensions
export const App = () => (
<Layout layout={Grid.col({ sm: 1, md: 50 })}>
<div>Child</div>
</Layout>
);Vue 3:
<script setup>
import { Layout } from 'rowscolumns/vue';
import 'rowscolumns';
</script>
<template>
<Layout :layout="Grid.col(1/2, 1/2)">
<div>Left</div>
<div>Right</div>
</Layout>
</template>Angular:
Initialize the engine in your main.ts and use a directive to trigger Engine.render(el). See the Full Documentation for the Angular Directive boilerplate.
- IDE Autocomplete: Fully typed for TypeScript and VS Code support.
- Zero Dependencies: Extremely lightweight and fast.
- Mathematical: No more guessing pixel widths; use native fractions and decimals.
- Responsive: Handle all screen sizes inline without complex media queries.
- Autocomplete: Fully typed for IDE support.
- Zero Dependencies: Lightweight and fast.
- Real-time: Reacts to window resizing automatically.
- Mathematical: No more guessing pixel widths or complex media queries.
License: MIT Β© [Abhimm5]