Getting Started
Getting started with USWDS + Tailwind is fast and easy. By copying and pasting the following snippets, you'll be up and running in minutes.
-
Setup
Initialize your project
Terminal window mkdir my-project && cd my-projectnpm init -yInstall dependencies
This project requires installing a few dependencies to get started:
USWDS + Tailwind
Terminal window npm i @uswds-tailwind/compat @uswds-tailwind/themeTailwind and plugins
Terminal window npm i tailwindcss @tailwindcss/vite @iconify-json/fa-solid @iconify-json/fa6-brands @iconify-json/material-symbolsInstall fonts
Terminal window npm i @fontsource-variable/open-sans @fontsource-variable/public-sans @fontsource-variable/roboto-mono @fontsource-variable/source-sans-3 @fontsource-variable/merriweather -
Project structure
Now that we’ve installed our necessary dependencies, let’s build out our project structure and finish setting up our various configurations.
Terminal window mkdir {src,src/assets,src/assets/js,src/assets/css}touch src/index.html src/assets/js/main.js src/assets/css/styles.css .gitignoreYour project structure should look like this:
my-project/├── node_modules/├── src/│ ├── assets/│ │ ├── js/| | │ └── main.js│ │ └── css/| | └── styles.css| └── index.html├── package-lock.json└── package.json -
Configure project
CSS
Then, import your fonts, Tailwind, and the
@uswds-tailwind/themedirectives into yoursrc/assets/css/styles.cssfile.src/assets/css/styles.css /* Only import the fonts you need! */@import "@fontsource-variable/open-sans";@import "@fontsource-variable/public-sans";@import "@fontsource-variable/roboto-mono";@import "@fontsource-variable/source-sans-3";@import "@fontsource-variable/merriweather";@import "tailwindcss";@import "@uswds-tailwind/theme";JavaScript
Now, update your
src/assets/js/main.jsfile to initialize your JavaScript components.More information about component specific plugins can be found on the JavaScript page.src/assets/js/main.js // Option 1: Auto-initialize all componentsimport '@uswds-tailwind/compat/auto'// Option 2: Manual initialization with only the components you needimport { modalInit, accordionInit } from '@uswds-tailwind/compat'document.addEventListener('DOMContentLoaded', () => {modalInit()accordionInit()})Finally, update your
src/index.htmlwith the following:src/index.html <!doctype html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>USWDS + Tailwind</title><link rel="stylesheet" href="../build/css/styles.css" /></head><body class="font-source-sans"><div class="py-4 px-3 mx-auto max-w-screen-desktop"><h1 class="text-4xl font-bold max-w-prose mb-4">Welcome to USWDS + Tailwind!</h1><buttontype="button"class="rounded-sm font-bold leading-none cursor-pointer text-white px-5 py-3 bg-blue-60v hover:bg-blue-warm-70v active:bg-blue-warm-80v focus:outline-4 focus:outline-offset-4 focus:outline-blue-40v">Default</button></div><script type="module" src="../assets/js/main.js"></script></body></html>.gitignore
Before we push any code to our repository, we’ll want to add a
.gitignorefile. This way, we dont push unnecessary or redundant code to our remote repository.Our
.gitignoreshould include the following:.gitignore node_modules.parcel-cachebuildIf you’re manually compiling your CSS and JavaScript assets locally before a deployment, don’t add the
builddirectory to your.gitignore. -
Complete!
Awesome, now everything is set up! You can run
npm run devand open theindex.htmlfile to see your project in action!If you’re using any of the interactive components that require JavaScript, head to the JavaScript page to see how to implement the various plugins.