Notes on Atomic Design

Our components employ the concept of atomic design, meaning that we break them down into atoms, molecules, and organisms, each successive level being more complex than the previous. (We do not currently use the template or page concepts as described in Brad Frost's seminal article introducing atomic design).

Our components are composed (on the front-end) of HTML, Less, and JavaScript. If a component doesn’t have user interactions or require styling, then it won’t have an associated JS and/or Less file. Components that are available for adding to a Wagtail page also require some Python programming—see the creating and editing components page for details.

We compose our atomic components as follows:


The smallest kind of component. May not contain any other components. Prefixed with a- in class names.


<div class="a-tag">Tag label {{ svg_icon('error') }}</div>


.a-tag {
    cursor: default;
    display: inline-block;
    padding: 5px 10px;


None of our atoms require any JavaScript at this time.


The medium-sized component. May contain atoms. Prefixed with m- in class names.


  {{ svg_icon('error') }}
  <div class="m-notification__content" role="alert">
    <div class="m-notification__message">Page not found.</div>


.m-notification {
    display: none;
    position: relative;
    padding: @notification-padding-px;


const BASE_CLASS = 'm-notification';
function Notification( element ) {
  // Constants for the state of this Notification.
  const SUCCESS = 'success';
  const WARNING = 'warning';
  const ERROR = 'error';

  // Constants for the Notification modifiers.
  const MODIFIER_VISIBLE = BASE_CLASS + '__visible';
  const _dom = atomicHelpers.checkDom( element, BASE_CLASS );
  const _contentDom = _dom.querySelector( '.' + BASE_CLASS + '_content' );

The Notification molecule can be instantiated by adding the following to your project's JavaScript code:

const notification = new Notification(_dom);


The largest component. May contain atoms, molecules, or (if no other solution is viable) other organisms. Prefixed with o- in class names.


<div class="o-expandable">
  <button class="o-expandable__header">
    <div class="o-expandable__label">…</div>


.o-expandable {
    position: relative;

    &__header {
        padding: 0;
        border: 0;


const BASE_CLASS = 'o-expandable';
function Expandable( element ) {
  // Bitwise flags for the state of this Expandable.
  const COLLAPSED = 0;
  const COLLAPSING = 1;
  const EXPANDING = 2;
  const EXPANDED = 3;

  // The Expandable element will directly be the Expandable
  // when used in an ExpandableGroup, otherwise it can be the parent container.
  const _dom = atomicHelpers.checkDom( element, BASE_CLASS );
  const _target = _dom.querySelector( '.' + BASE_CLASS + '_header' );
  const _content = _dom.querySelector( '.' + BASE_CLASS + '_content' );

The Expandable organism can be instantiated by adding the following to your project's JavaScript code:

const expandable = new Expandable(_dom.querySelector('.o-expandable'));


import { instantiateAll } from '@cfpb/cfpb-atomic-component';
import { Expandable } from '@cfpb/cfpb-expandables';
instantiateAll('.o-expandable', Expandable);

Folder structure

Our atomic components are separated and named based on asset type. HTML, Less, and JavaScript for each component are in separate directories.



Some of our foundational components get their Less and JavaScript from the Design System, but the HTML for their Wagtail block templates is stored in the above folders.




JavaScript architecture

JavaScript components are built to be rendered on the server and then enhanced via JavaScript on the client. The basic interface for the components is as follows:

function AtomicComponent(domElement) {
  // Ensure the passed in Element is in the DOM.
  // Query and store references to sub-elements.
  // Instantiate child atomic components.
  // Bind necessary events for referenced DOM elements.
  // Perform other initialization related tasks.
  this.init = function init() {};

  // General teardown function
  // We don't remove the element from the DOM so
  // we need to unbind the events.
  this.destroy = function destroy() {};

We generally favor composition over inheritance. You can get more information by reading the following:

Component build pipeline


Routes are used to serve JavaScript bundles to the browser based on the requested URL or Wagtail page's Media definition. This happens via code contained in v1/layouts/base.html. This file serves as the base HTML template for serving Wagtail pages.

Wagtail page Media class

Each atomic component has a Media class that lists the JavaScript files that should be loaded via base.html. When a page is requested via the browser, code contained in base.html will loop all atomic components for the requested page and load the appropriate atomic JavaScript bundles.

Here is an example of the Media class on a component, the EmailSignUp organism:

class Media:
    js = ['email-signup.js']

This will load the email-signup.js script on any page that includes the EmailSignUp organism in one of its StreamFields.