Pure HTML and CSS, no JavaScript.
Rather than controlling layout properties via class name, it is possible to safely use attributes on any element with a valid custom-element name, such as x-grid
, even if that element is not defined in the CustomElementRegistry.
By leveraging [attr~=value]
CSS selectors, one can construct complex responsive utilities based on whitespace-separated attributes. Combining these two techniques results in a powerful, expressive API that is simple to use and requires JavaScript or SSR considerations.
A responsive attribute consists of a value (most often an <integer>
), and one or more responsive values prefixed by a breakpoint and colon (sm:
, md:
, lg:
, xl:
).
<x-grid gap="4 sm:8 md:16 lg:24 xl:32" />
Attributes
cols
is a responsive attribute representing the number of columns per row at a given breakpoint.gap
is a responsive attribute which accepts an<integer>
following Tailwind's default spacing scale (but named after the pixel values rather than the scale name). It applies bothrow-gap
andcolumn-gap
properties.dense
is a boolean attribute which enablesdense
packing inside of the grid.
Custom Properties
--row-height
determines the height of all rows in the grid.--col-ratio
applies anaspect-ratio
tox-col
elements as an alternative to setting--row-height
.--row-gap
applies a specificrow-gap
value.--col-gap
applies a specificcolumn-gap
value.
Attributes
span
is a responsive attribute which accepts1-12|row
, representing the number of columns to span. Defaults to1
.start
is a responsive attribute representing the column on which to start. Defaults toauto
.end
is a responsive attribute representing the column on which to end. Defaults toauto
. Note that this<integer>
represents the end track of a column (soend="8"
will stretch up until column 9.)