SmolCSS Patterns Demo

A demonstration of small, effective CSS layout patterns using custom properties. Loosely inspired by the SmolCSS

CSS Properties Reference Guide

A quick reference of all custom properties used in SmolCSS patterns.

Container

  • --smol-container-padding: 1.5rem
  • --smol-container-max-width: 60ch

Grid

  • --smol-grid-min-item-width: 15ch
  • --smol-grid-gap: 1rem

Flexbox Grid

  • --smol-flex-min-item-width: 10ch
  • --smol-flex-gap: 1rem

Columns

  • --smol-columns-count: 2
  • --smol-columns-width: 15ch
  • --smol-columns-gap: 1rem

Switcher

  • --smol-switcher-threshold: 30rem
  • --smol-switcher-gap: 1rem
  • --smol-switcher-space: 0

Stack

  • --smol-stack-gap: 1rem
  • --smol-stack-recursive-gap: 0.5rem

Box

  • --smol-box-padding: 1rem
  • --smol-box-border-radius: 0.25rem
  • --smol-box-border-width: 1px
  • --smol-box-border-color: #ddd

Center

  • --smol-center-padding: 1rem
  • --smol-center-max-width: 60ch
  • --smol-center-text-align: left

Sidebar

  • --smol-sidebar-gap: 1rem
  • --smol-sidebar-min-content-width: 50%
  • --smol-sidebar-sidebar-width: 20ch

Cluster

  • --smol-cluster-gap: 1rem
  • --smol-cluster-justify: flex-start
  • --smol-cluster-align: center

Frame

  • --smol-frame-height: auto
  • --smol-frame-width: 100%
  • --smol-frame-aspect-ratio: 16/9

Breakout

  • --smol-breakout-max-width: (60ch + 40vw)

Flow

  • --smol-flow-spacing: 1em

Cover

  • --smol-cover-min-height: 100vh
  • --smol-cover-padding: 1rem
  • --smol-cover-gap: 1rem

1. Responsive Container

A centered container with responsive padding that maxes out at a comfortable reading width.

CSS Properties

  • --smol-container-padding: Space on the sides (1.5rem)
  • --smol-container-max-width: Maximum width (60ch)

This works by using the min() function with two values:

  1. Full width minus padding (100% - padding*2)
  2. Max width (var(--smol-container-max-width))

I'm a responsive container that's centered with padding and a max-width.

2. Auto Grid

A responsive grid layout that automatically adjusts the number of columns based on available space.

CSS Properties

  • --smol-grid-min-item-width: Minimum width for each item (15ch)
  • --smol-grid-gap: Space between grid items (1rem)

This works by using CSS Grid with auto-fit and minmax():

Grid Item 1
Grid Item 2
Grid Item 3
Grid Item 4
Grid Item 5
Grid Item 6

3. Flexbox Grid

A flexible grid layout using flexbox that allows items to grow and wrap naturally.

CSS Properties

  • --smol-flex-min-item-width: Base size for flex items (10ch)
  • --smol-flex-gap: Space between flex items (1rem)

This works through flexbox:

Flex Item 1
Flex Item 2
Flex Item 3
Flex Item 4
Flex Item 5

4. Multi-column Layout

A layout that automatically divides content into multiple columns for better readability.

CSS Properties

  • --smol-columns-count: Number of columns (2)
  • --smol-columns-width: Minimum column width (15ch)
  • --smol-columns-gap: Space between columns (1rem)

This uses CSS Multi-column Layout:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget enim vel nisi commodo lacinia. Proin volutpat, velit eu pharetra pellentesque, nisi sem convallis magna, at facilisis eros nulla id purus.

Suspendisse sed odio quis nulla pretium convallis. Fusce ut ex eget orci fermentum lacinia. Vivamus ac fringilla ex, ac pharetra tellus. Sed quis sagittis lorem.

Curabitur rhoncus, quam id tempus faucibus, felis urna efficitur justo, at mattis sapien eros in nisl. Nam luctus diam eu felis lacinia, quis tristique elit elementum.

Donec pharetra ultrices purus, vel interdum nibh interdum quis. Integer pretium eu ligula sed volutpat. Nullam sit amet placerat leo, quis porttitor nulla.

5. Switcher

A layout that switches between horizontal and vertical arrangement based on available space.

CSS Properties

  • --smol-switcher-threshold: Width at which layout switches (30rem)
  • --smol-switcher-gap: Space between items (1rem)

This works through a clever flexbox technique:

Switcher Item 1
Switcher Item 2

6. Stack

A simple vertical stack with consistent spacing between elements.

CSS Properties

  • --smol-stack-gap: Space between direct children (1rem)
  • --smol-stack-recursive-gap: Space between all nested children (0.5rem) when using recursive variant

This works by:

Stack Item 1
Stack Item 2
Stack Item 3

7. Box

A simple bordered container with padding.

CSS Properties

  • --smol-box-padding: Internal padding (1rem)
  • --smol-box-border-radius: Corner radius (0.25rem)
  • --smol-box-border-width: Border thickness (1px)
  • --smol-box-border-color: Border color (#ddd)

This is a simple component that applies consistent styling to create a box container.

I'm content inside a box component with consistent padding and border styling.

8. Center

A component for horizontally centering content with a maximum width.

CSS Properties

  • --smol-center-max-width: Maximum content width (60ch)
  • --smol-center-padding: Horizontal padding (1rem)
  • --smol-center-text-align: Text alignment (left)

This works by:

This content is centered horizontally with a maximum width for optimal readability.

10. Cluster

A flexible layout for grouping related items with consistent spacing.

CSS Properties

  • --smol-cluster-gap: Space between items (1rem)
  • --smol-cluster-justify: Horizontal alignment (flex-start)
  • --smol-cluster-align: Vertical alignment (center)

This uses flexbox with wrapping:

Item 1
Longer Item 2
Item 3
Very Long Item 4
Item 5

11. Frame

A responsive container that maintains a specific aspect ratio for media.

CSS Properties

  • --smol-frame-aspect-ratio: Width to height ratio (16/9)
  • --smol-frame-width: Width of the media (100%)
  • --smol-frame-height: Height of the media (auto)

This works by:

16:9 Media Container

12. Breakout

A component that breaks out of the content flow to span the full viewport width.

CSS Properties

  • --smol-breakout-max-width: Maximum width for the breakout (--smol-max-width + 40vw)

This works through creative positioning:

Normal width content above

I break out of the container and span the full viewport width!

Normal width content below

13. Flow

A simple utility for adding consistent vertical spacing between elements.

CSS Properties

  • --smol-flow-spacing: Space between flow items (1em)

This works by:

First paragraph in the flow.

Second paragraph with consistent spacing above.

Third paragraph with the same spacing.

  • A list item in the flow
  • Another list item

Final paragraph with consistent spacing.

14. Cover

A layout that covers the full viewport height with centered content.

CSS Properties

  • --smol-cover-min-height: Minimum height (100vh)
  • --smol-cover-padding: Internal padding (1rem)
  • --smol-cover-gap: Space between elements (1rem)

This works by:

I'm at the top
I'm centered vertically
I'm at the bottom