Skip to content
Content Blocks
Build websites from blocks, not scratch A web components library for building your next perfectly responsive content website.

Integrates with Wordpress, Shopify, headless CMS integrations, and more.
npm install @content-blocks/js

1 / 3A basic hero block: a looping video, and a vertically centered text block.

<content-hero-block id="hero">
  <content-image slot="background"
    src="embers.mp4">
  </content-image>
  <content-text-block slot="content" vertical="center">
    <h1>The Warden Returns</h1>
  </content-text-block>
</content-hero-block>

The Warden Returns

Watch the omen
Responsive props Every property can be configured per breakpoint letting you build perfectly responsive websites with minimal CSS.

Define a value per breakpoint

Build perfectly responsive sites easily without having to manage CSS or media queries. Integrate with your favorite headless CMS easily.

  • columns="1|2|4"
  • columns="1|tablet=2"
  • columns="1|640=2"

Enhance basic elements

Add the responsive functionality that HTML is missing. An image can show a photo, a video, or a looping .mp4 like a GIF, and change between them per breakpoint.

  • src="photo.jpg|clip.mp4"A light photo on phones, a looping video on bigger screens.

Responsive behavior

Components change how they work at each breakpoint, not only how they look.

  • fill="body|#hero"A film opens full screen on phones, and plays inside the hero on desktop.
Edit any value, and hover or focus one to see it filled out per breakpoint
<content-image
  src=""
  aspect-ratio="">
</content-image>

<content-grid-formatter columns="">
  …
</content-grid-formatter>
Elements Components for displaying content.

<content-line>

Line

One line of text, such as a heading or a paragraph, with its tag, alignment and maximum width set per breakpoint.

  • Use responsive props to control display across breakpoints
The horn has sounded centered from 768px, left on phones.
Show the code
<content-line tag="h3" text-align="left|center">The horn has sounded</content-line>
<content-line tag="p" text-align="left|center" padding="0.4rem 0 0">centered from 768px, left on phones.</content-line>
h3 {
  font-size: 1.5rem;
  font-weight: 700;
}
Line docs

<content-image>

Image

A responsive image or muted looping video per breakpoint with native lazy loading.

  • A different source and crop per breakpoint
  • Plays a muted .mp4 on a loop, like a GIF
  • Native lazy loading and fetch priority
Show the code
<content-image
  alt=""
  src="https://videos.pexels.com/video-files/1879456/1879456-sd_640_360_30fps.mp4"
  aspect-ratio="1/1|16/9"
></content-image>
Image docs

<content-button>

Button

A link or button. Wrapped around block content, such as a card, it makes the whole area clickable, and opens a content-overlay when its href points at one.

  • A link, or a button when it has no href
  • Makes a whole card clickable
  • Opens the overlay its href points at
Answer the call
Show the code
<content-button>Answer the call</content-button>
content-button a {
  padding: 0.5rem 1rem;
  color: #fff;
  text-decoration: none;
  background: #1d4ed8;
}
Button docs

<content-video>

Video

A video player for YouTube or self hosted files, built on Video.js.

  • YouTube or self hosted files, on Video.js
  • Fits the overlay or block it plays in
  • Starts muted when an overlay opens it
▶
Show the code
<content-hero-block id="el-video">
  <content-image slot="background" alt="" src="https://videos.pexels.com/video-files/20706803/20706803-sd_640_360_25fps.mp4" aspect-ratio="16/9"></content-image>
  <content-text-block slot="content" vertical="center" text-align="center">
    <content-button href="#el-video-film" link-label="Play the omen">▶</content-button>
  </content-text-block>
</content-hero-block>
<content-overlay id="el-video-film" fill="#el-video" label="The omen">
  <script slot="content" type="text/template">
    <content-video fit-container="true" autoplay="true" src="https://www.youtube.com/watch?v=eRsGyueVLvQ"></content-video>
  </script>
</content-overlay>
content-button a {
  width: 3.25rem;
  height: 3.25rem;
  color: #111;
  text-decoration: none;
  background: #fff;
  border-radius: 50%;
}
Video docs
Blocks The four sections most content pages are made of. Each block lays itself out at every breakpoint, so a page is only content.

<content-hero-block>

Hero

A full width section with an image or video behind, or above, its text. Usually the first block on a page.

  • An image or a muted looping video behind the text
  • Text below the media on phones, over it from 768px
  • Opens a film over itself with content-overlay
The mountain wakes
Show the code
<content-hero-block>
  <content-image slot="background" alt="" src="https://videos.pexels.com/video-files/9882072/9882072-sd_640_360_30fps.mp4" aspect-ratio="16/10"></content-image>
  <content-text-block slot="content" vertical="center" text-align="center" padding="1rem">
    <content-line tag="h3">The mountain wakes</content-line>
  </content-text-block>
</content-hero-block>
h3 {
  font-size: 1.5rem;
  font-weight: 700;
}
content-text-block {
  color: #fff;
  background: rgb(0 0 0 / 40%);
}
Hero docs

<content-split-block>

Split

Two columns side by side, such as an image next to text, that stack on smaller screens.

  • Two columns that stack on phones
  • Swaps sides per breakpoint with reverse
  • Images, video or text in either column
The valley waits for its hero.
Show the code
<content-split-block columns="2">
  <content-image slot="column1" alt="" src="https://videos.pexels.com/video-files/4763084/4763084-sd_640_360_24fps.mp4" aspect-ratio="1/1"></content-image>
  <content-text-block slot="column2" vertical="center" padding="0.75rem">
    <content-line tag="p">The valley waits for its hero.</content-line>
  </content-text-block>
</content-split-block>
content-split-block {
  color: #fff;
  background: #1d4ed8;
}
Split docs

<content-text-block>

Text

A block of text with its alignment, vertical position and minimum height set per breakpoint.

  • Text alignment per breakpoint
  • Pins its content to the top, center or bottom
  • A minimum height, and a footer slot
Prophecy The Warden returns at winter’s end
Show the code
<content-text-block min-height="140px" vertical="bottom" padding="1.25rem">
  <content-line tag="h4">Prophecy</content-line>
  <content-line tag="h3" padding="0.25rem 0 0">The Warden returns at winter’s end</content-line>
</content-text-block>
h3 {
  font-size: 1.5rem;
  font-weight: 700;
}
content-text-block {
  color: #fff;
  background: #0f172a;
}
h4 {
  font-size: 0.75rem;
  font-weight: 700;
}
Text docs

<content-tout-block>

Tout

A card that promotes something: an image or video with text below it, and an optional layer over the media that can show on hover.

  • Media with its text below
  • A layer over the media, always on or on hover
  • The whole card one link, inside content-button
The last forge still burns
Show the code
<content-tout-block hover="false">
  <content-image slot="media" alt="" src="https://videos.pexels.com/video-files/12298312/12298312-sd_640_360_24fps.mp4" aspect-ratio="16/9"></content-image>
  <content-text-block slot="content" padding="0.6rem 0 0">
    <content-line tag="p"><strong>The last forge still burns</strong></content-line>
  </content-text-block>
</content-tout-block>
Tout docs
More components to explore Space and grids to place the blocks, and the accordions, carousels, menus, overlays and tabs that pages need.

<content-accordion>

Accordion

A button that shows and hides the content below it, such as an answer in a list of questions.

When does the hero return?

When the horn sounds.

Can Ragnarök be stopped?

Only if we stand together.

Show the code
<content-accordion>
  <span slot="trigger">When does the hero return?</span>
  <p>When the horn sounds.</p>
</content-accordion>
<content-accordion>
  <span slot="trigger">Can Ragnarök be stopped?</span>
  <p>Only if we stand together.</p>
</content-accordion>
content-accordion > button {
  padding: 0.6rem 0;
  font-weight: 600;
  border-bottom: 1px solid #cbd5e1;
}
Accordion docs

<content-carousel>

Carousel

Slides that move sideways, built on Swiper, with labelled controls and a pause button when they move on their own.

Show the code
<content-carousel label="The realms in peril" swiper-options='{"slidesPerView": 1, "loop": true, "pagination": {"clickable": true}}'>
  <content-image alt="A castle rising out of a sea of fog" src="https://images.unsplash.com/photo-1515688272562-004db9d10783?w=480&h=270&fit=crop&auto=format&q=70" aspect-ratio="16/9"></content-image>
  <content-image alt="A pack of wolves running through a snowy forest" src="https://images.unsplash.com/photo-1552249007-6759fe2742b6?w=480&h=270&fit=crop&auto=format&q=70" aspect-ratio="16/9"></content-image>
  <content-image alt="A raven flying low over snow" src="https://images.unsplash.com/photo-1610961388965-129b15e46a2c?w=480&h=270&fit=crop&auto=format&q=70" aspect-ratio="16/9"></content-image>
</content-carousel>
Carousel docs

<content-grid-formatter>

Grid

Lays its children out in a grid or a row, with the number of columns, gaps and alignment set per breakpoint.

1 2 3 4 5 6
Show the code
<content-grid-formatter type="grid" columns="2|3" column-gap="0.5rem" row-gap="0.5rem">
  <content-line>1</content-line>
  <content-line>2</content-line>
  <content-line>3</content-line>
  <content-line>4</content-line>
  <content-line>5</content-line>
  <content-line>6</content-line>
</content-grid-formatter>
content-line {
  padding: 0.6rem;
  color: #fff;
  background: #1d4ed8;
}
Grid docs

<content-navigation-block>

Navigation

Site navigation that collapses into a menu button on the breakpoints you choose, with a skip link for keyboard users.

Show the code
<header>
  <content-grid-formatter vertical="center" column-gap="1rem" padding="0.75rem 1rem">
    <content-line tag="p" flex-grow="true"><strong>Hollowmere</strong></content-line>
    <content-navigation-block hamburger="fixed" flex-shrink="true">
      <a slot="skipContent" href="#more-after-nav">Skip navigation</a>
      <nav slot="content" aria-label="Demo">
        <content-grid-formatter direction="column" row-gap="1rem" padding="1.5rem 0 0">
          <a href="#more">The saga</a>
          <a href="#more">The realms</a>
          <a href="#more">Take the oath</a>
        </content-grid-formatter>
      </nav>
    </content-navigation-block>
  </content-grid-formatter>
</header>
<span id="more-after-nav"></span>
header {
  color: #fff;
  background: #0f172a;
  --content-navigation-background: #0f172a;
}
a {
  color: #fff;
  text-decoration: none;
}
Navigation docs

<content-overlay>

Overlay

A dialog that opens over the page, or inside another element, and keeps keyboard focus inside it while open.

Read the prophecy
Show the code
<content-text-block id="more-overlay" min-height="140px" vertical="center" text-align="center">
  <content-button href="#more-dialog">Read the prophecy</content-button>
</content-text-block>
<content-overlay id="more-dialog" fill="#more-overlay" label="The prophecy">
  <script slot="content" type="text/template">
    <content-line tag="p" padding="1rem">When the wolf swallows the sun, the Warden will return.</content-line>
  </script>
</content-overlay>
content-button a {
  padding: 0.5rem 1rem;
  color: #fff;
  text-decoration: none;
  background: #1d4ed8;
}
content-overlay {
  background: #fff;
}
Overlay docs

<content-spacer>

Spacer

Adds space around its content and limits its width, with its padding and maximum width set per breakpoint.

190px wide, centered
Show the code
<content-spacer padding="1rem" max-width="190px" horizontal="center">
  <content-line tag="p" text-align="center">190px wide, centered</content-line>
</content-spacer>
content-spacer {
  color: #fff;
  background: #1d4ed8;
}
Spacer docs

<content-tabs>

Tabs

Accessible tabs: a tablist of buttons and the panels they show, with arrow key support.

Rising from the sea.
Show the code
<content-tabs>
  <div role="tablist" aria-label="The foes">
    <button role="tab" id="more-tab-monthly" aria-selected="true" aria-controls="more-panel-monthly">The serpent</button>
    <button role="tab" id="more-tab-yearly" aria-selected="false" aria-controls="more-panel-yearly" tabindex="-1">The wolf</button>
  </div>
  <div role="tabpanel" id="more-panel-monthly" aria-labelledby="more-tab-monthly" tabindex="0">
    <content-line tag="p" padding="1rem 0 0">Rising from the sea.</content-line>
  </div>
  <div role="tabpanel" id="more-panel-yearly" aria-labelledby="more-tab-yearly" tabindex="0" hidden>
    <content-line tag="p" padding="1rem 0 0">Straining at the chain.</content-line>
  </div>
</content-tabs>
[role='tablist'] {
  display: flex;
  gap: 1.25rem;
  border-bottom: 1px solid #cbd5e1;
}
[role='tab'] {
  padding: 0.5rem 0;
  font: inherit;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
}
[role='tab'][aria-selected='true'] {
  color: #1d4ed8;
  border-bottom: 2px solid #1d4ed8;
}
Tabs docs
Why Content Blocks

Responsive by attribute

Each option takes a value per breakpoint on the tag itself, such as columns="1|2|4", and the component lays itself out.

  • A headless CMS can control the responsive layout, because each breakpoint is just a text field
  • Editors change columns, crops and order per screen size without waiting on a developer or a deploy
  • New pages need no new media queries or one-off CSS
Your editors control the layout Every screen size is just another field in your CMS. Change the entry and the page lays itself out again, with no developer, no CSS and no deploy.
PhoneTabletDesktop
src
content-position
vertical
text-align
Stored in your CMS
{
  "block": "content-hero-block",
  "heading": "The Warden returns",
  "text": "Nine winters the north gate has held. Now the horn sounds, and one rider answers.",
  "media": "warden.jpg|lava.mp4",
  "alt": "A bearded warrior in a steel helm|tablet=",
  "contentPosition": "below|above",
  "vertical": "center|center|bottom",
  "textAlign": "center|center|left"
}
Your template
export function Section({ entry }) {
  return (
    <content-hero-block content-position={entry.contentPosition}>
      <content-image slot="background" src={entry.media} alt={entry.alt}
        aspect-ratio="4/3|16/9|21/9">
      </content-image>
      <content-text-block slot="content" vertical={entry.vertical} text-align={entry.textAlign}>
        <content-line tag="h1">{entry.heading}</content-line>
        <content-line tag="p">{entry.text}</content-line>
      </content-text-block>
    </content-hero-block>
  );
}
Rendered on your site
<content-hero-block content-position="below|above">
  <content-image slot="background" src="warden.jpg|lava.mp4" alt="A bearded warrior in a steel helm|tablet="
    aspect-ratio="4/3|16/9|21/9">
  </content-image>
  <content-text-block slot="content" vertical="center|center|bottom" text-align="center|center|left">
    <content-line tag="h1">The Warden returns</content-line>
    <content-line tag="p">Nine winters the north gate has held. Now the horn sounds, and one rider answers.</content-line>
  </content-text-block>
</content-hero-block>
Get started
From a CDN: each component loads the first time its tag appears
<script type="module"
  src="https://cdn.jsdelivr.net/npm/@content-blocks/js/dist/content-blocks/content-blocks.esm.js">
</script>
From npm: import the loader, or one component at a time
$ npm install @content-blocks/js
Works with all of these, and more, because they are just web components

HTML

React

Vue

Astro

Next.js

Docs and FAQs

Resources

FAQs

Do I need a framework?No. Content Blocks are standard custom elements, so a single script tag is enough. They also work inside React, Vue, Astro, Next.js and any other framework that renders HTML.How much JavaScript does it add?The loader is about 2 KB gzipped. Each component's code loads only the first time its tag appears on the page, so a page pays only for the components it uses. With npm you can also import components one at a time.Is it good for SEO?The components render in the light DOM, with no shadow DOM, so your headings, copy, links and images stay in the page's HTML where search engines read them.Can I use my own design?Yes. The components handle layout, spacing and behaviour, and your own stylesheet sets the look. Every component also takes a classes prop for your own class names.How do breakpoints work?Responsive props take a base value, then a value for each breakpoint where it changes: 1|tablet=2|desktop=4 is one on phones, two from 768px and four from 1366px. The breakpoints are named mobile, tablet, laptop, desktop, wide and ultrawide by default, and you can set your own names and widths in one line.Which CMS does it work with?Any headless CMS that can store text fields. A block is a tag and a few text values, so it fits whatever content model you already have, and your front end renders it as HTML.Is it accessible?Keyboard support, focus handling in dialogs, labelled carousels with a pause button and lazy loaded images are built in, and every component is tested with axe. Your content still needs good alt text and heading order.Does it work with TypeScript and my editor?Yes. The package ships TypeScript types, and a VS Code data file adds autocomplete for every tag and prop.Is it ready for production?Content Blocks is at version 0.8. Every release is versioned and listed in the changelog, so you can pin a version and upgrade when you are ready.What does it cost?Nothing. Content Blocks is open source under the MIT license.