1 | # U.S. Web Design System
|
2 |
|
3 | [![CircleCI Build Status](https://circleci.com/gh/uswds/uswds/tree/develop.svg?style=shield)](https://circleci.com/gh/uswds/uswds/tree/develop) [![Test Coverage](https://api.codeclimate.com/v1/badges/c10cd4505d61d161cd3a/test_coverage)](https://codeclimate.com/github/uswds/uswds/test_coverage)
|
4 |
|
5 | The [U.S. Web Design System](https://designsystem.digital.gov) includes a library of open source UI components and a visual style guide for U.S. federal government websites.
|
6 |
|
7 | This repository is for the Design System itself. We maintain [another repository for the documentation and website](https://github.com/uswds/uswds-site). To see the Design System and documentation on the web, visit [https://designsystem.digital.gov](https://designsystem.digital.gov).
|
8 |
|
9 | ## Contents
|
10 |
|
11 | * [Background](#background)
|
12 | * [Recent updates](#recent-updates)
|
13 | * [Getting started](#getting-started)
|
14 | * [Using the Design System](#using-the-design-system)
|
15 | * [Download](#download)
|
16 | * [Install using `npm`](#install-using-npm)
|
17 | * [Importing assets](#importing-assets)
|
18 | * [Sass](#sass)
|
19 | * [JavaScript](#javascript)
|
20 | * [Use another framework or package manager](#use-another-framework-or-package-manager)
|
21 | * [CSS architecture](#css-architecture)
|
22 | * [JS customization](#js-customization)
|
23 | * [Customization and theming](#customization-and-theming)
|
24 | * [Set the base asset path (fonts and images)](#set-the-base-asset-path-fonts-and-images)
|
25 | * [Main variables that can be customized](#main-variables-that-can-be-customized)
|
26 | * [Where things live](#where-things-live)
|
27 | * [Browser support](#browser-support)
|
28 | * [Accessibility](#accessibility)
|
29 | * [Fractal](#fractal)
|
30 | * [Template compatibility](#template-compatibility)
|
31 | * [Need installation help?](#need-installation-help)
|
32 | * [Contributing to the code base](#contributing-to-the-code-base)
|
33 | * [Reuse of open-source style guides](#reuse-of-open-source-style-guides)
|
34 | * [Licenses and attribution](#licenses-and-attribution)
|
35 |
|
36 | ## Background
|
37 |
|
38 | The components and style guide of the U.S. Web Design System follows industry-standard web accessibility guidelines and use the best practices of existing style libraries and modern web design. The [U.S. Digital Service](https://www.whitehouse.gov/digital/united-states-digital-service) and [18F](https://18f.gsa.gov/) created the U.S. Web Design System for designers and developers. The U.S. Web Design System is a project of GSA’s [Technology Transformation Service](https://www.gsa.gov/about-us/organization/federal-acquisition-service/technology-transformation-services), maintained by the Office of Products and Programs. They are designed for use by government product teams who want to create beautiful, easy-to-use online experiences for the public. To learn more about the project, check out this [blog post](https://18f.gsa.gov/2015/09/28/web-design-standards/) and to view websites and applications check out our list [here](docs/WHO_IS_USING_USWDS.md).
|
39 |
|
40 |
|
41 | ## Recent updates
|
42 |
|
43 | Information about the most recent release of the Design System can always be found in the [release history](https://github.com/uswds/uswds/releases). We include details about significant updates and any backwards incompatible changes along with a list of all changes.
|
44 |
|
45 |
|
46 | ## Getting started
|
47 |
|
48 | We’re glad you’d like to use the Design System — here’s how you can get started:
|
49 |
|
50 | * Designers: [Check out our Getting Started for Designers information](https://designsystem.digital.gov/getting-started/designers/).
|
51 | * [Design files of all the assets included in the Design System are available for download](https://github.com/uswds/uswds-assets/archive/master.zip).
|
52 | * Developers: [Follow the instructions in this README to get started.](#using-the-design-system)
|
53 | * [CSS, JavaScript, image, and font files of all the assets on this site are available for download](https://github.com/uswds/uswds/releases/latest).
|
54 |
|
55 |
|
56 | ## Using the Design System
|
57 |
|
58 | There are a few different ways to use the Design System within your project. Which one you choose depends on the needs of your project and how you are most comfortable working. Here are a few notes on what to consider when deciding which installation method to use:
|
59 |
|
60 | *Download the Design System if:*
|
61 | - You are not familiar with `npm` and package management.
|
62 |
|
63 | *Use the Design System `npm` package if:*
|
64 | - You are familiar with using `npm` and package management.
|
65 |
|
66 | ### Download
|
67 |
|
68 | 1. Download the [USWDS zip file](https://github.com/uswds/uswds/releases/latest) from the latest release and open that file.
|
69 |
|
70 | After extracting the zip file you should see the following file and folder structure:
|
71 |
|
72 | ```
|
73 | uswds-1.0.0/
|
74 | ├── css/
|
75 | │ ├── uswds.min.css.map
|
76 | │ ├── uswds.min.css
|
77 | │ └── uswds.css
|
78 | ├── fonts/
|
79 | ├── img/
|
80 | ├── js/
|
81 | │ ├── uswds.min.js.map
|
82 | │ ├── uswds.min.js
|
83 | │ └── uswds.js
|
84 | └── scss/
|
85 |
|
86 | ```
|
87 |
|
88 | 2. Copy these files and folders into a relevant place in your project's code base. Here is an example structure for how this might look:
|
89 |
|
90 | ```
|
91 | example-project/
|
92 | ├── assets/
|
93 | │ ├── uswds-1.0.0/
|
94 | │ ├── stylesheets/
|
95 | │ ├── images/
|
96 | │ └── javascript/
|
97 | └── index.html
|
98 | ```
|
99 |
|
100 | You'll notice in our example above that we also outline a `stylesheets`, `images` and `javascript` folder in your `assets` folder. These folders are to help organize any assets that are unique to your project.
|
101 |
|
102 | 3. To use the Design System on your project, you’ll need to reference the [CSS (*C*ascading *S*tyle *S*heets)](https://developer.mozilla.org/en-US/docs/Web/CSS) and JavaScript files in each HTML page or dynamic templates in your project. (We also provide Sass (SCSS) files in the zip file which you can compile to CSS. See [Sass](#sass).)
|
103 |
|
104 | Here is an example of how to reference these assets in your `index.html` file:
|
105 |
|
106 | ```html
|
107 | <!DOCTYPE html>
|
108 | <html>
|
109 | <head>
|
110 | <meta charset="utf-8">
|
111 | <meta http-equiv="X-UA-Compatible" content="IE=edge">
|
112 | <title>My Example Project</title>
|
113 | <link rel="stylesheet" href="assets/uswds-1.0.0/css/uswds.min.css">
|
114 | </head>
|
115 | <body>
|
116 |
|
117 | <script src="assets/uswds-1.0.0/js/uswds.min.js"></script>
|
118 | </body>
|
119 | </html>
|
120 | ```
|
121 |
|
122 | We offer both files, the CSS and the JavaScript, in two versions — a minified version, and an un-minified one. (In the examples above, we are using the minified files.) Use the minified files in a production environment or to reduce the file size of your downloaded assets. And the un-minified files are better if you are in a development environment or would like to debug the CSS or JavaScript assets in the browser.
|
123 |
|
124 | And that’s it — you should now be able to copy our code samples into your `index.html` and start using the Design System.
|
125 |
|
126 | ### Install using npm
|
127 |
|
128 | `npm` is a package manager for Node based projects. The U.S. Web Design System maintains a [`uswds` package](https://www.npmjs.com/package/uswds) for you to utilize both the pre-compiled and compiled files on your project.
|
129 |
|
130 | 1. Install `Node/npm`. Below is a link to find the install method that coincides with your operating system:
|
131 |
|
132 | - Node v8.14.1, [Installation guides](https://nodejs.org/en/download/)
|
133 |
|
134 | **Note for Windows users:** If you are using Windows and are unfamiliar with `Node` or `npm`, we recommend following [Team Treehouse's tutorial](http://blog.teamtreehouse.com/install-node-js-npm-windows) for more information.
|
135 |
|
136 | 2. Make sure you have installed it correctly:
|
137 |
|
138 | ```shell
|
139 | npm -v
|
140 | 6.4.1 # This line may vary depending on what version of Node you've installed.
|
141 | ```
|
142 |
|
143 | 3. Create a `package.json` file. You can do this manually, but an easier method is to use the `npm init` command. This command will prompt you with a few questions to create your `package.json` file.
|
144 |
|
145 | 4. Add `uswds` to your project’s `package.json`:
|
146 |
|
147 | ```shell
|
148 | npm install --save uswds
|
149 | ```
|
150 |
|
151 | The `uswds` module is now installed as a dependency. You can use the un-compiled files found in the `src/` or the compiled files in the `dist/` directory.
|
152 |
|
153 | ```
|
154 | node_modules/uswds/
|
155 | ├── dist/
|
156 | │ ├── css/
|
157 | │ ├── fonts/
|
158 | │ ├── img/
|
159 | │ ├── js/
|
160 | │ └── scss/
|
161 | └── src/
|
162 | |── components/
|
163 | ├── fonts/
|
164 | ├── img/
|
165 | ├── js/
|
166 | └── stylesheets/
|
167 | ```
|
168 |
|
169 | #### Importing assets
|
170 |
|
171 | Since you are already using `npm`, the U.S. Web Design System team recommends leveraging the ability to write custom scripts. Here are some links to how we do this with our docs website using `npm` + [`gulp`](http://gulpjs.com/):
|
172 |
|
173 | [Link to `npm` scripts example in `uswds-site`](https://github.com/uswds/uswds-site/blob/master/package.json#L28)
|
174 |
|
175 | [Link to gulpfile.js example in `uswds-site`](https://github.com/uswds/uswds-site/blob/master/gulpfile.js)
|
176 |
|
177 | #### Sass
|
178 |
|
179 | The Design System is easily customizable using the power of [Sass (Syntactically Awesome Style Sheets)](http://sass-lang.com/). The main Sass (SCSS) source file is located here:
|
180 |
|
181 | ```
|
182 | node_modules/uswds/src/stylesheets/uswds.scss
|
183 | ```
|
184 |
|
185 | Global variables are defined in the `node_modules/uswds/src/stylesheets/core/_variables.scss` file. Custom theming can be done by copying the `_variables.scss` file into your own project’s Sass folder, changing applicable variable values, and importing it before `uswds.scss`.
|
186 |
|
187 | Below is an example of how you might setup your main Sass file to achieve this:
|
188 |
|
189 | ```scss
|
190 | @import 'variables.scss'; # Custom Sass variables file
|
191 | @import 'node_modules/uswds/src/stylesheets/uswds.scss';
|
192 | ```
|
193 |
|
194 | You can now use your copied version of `_variables.scss` to override any styles to create a more custom look and feel to your application.
|
195 |
|
196 | The Design System uses [gulp-autoprefixer](https://github.com/sindresorhus/gulp-autoprefixer) to automatically add vendor prefixes to the precompiled stylesheets (`css/uswds.min.css` and `css/uswds.css`) however prefixes will not be applied when using the Sass source files directly. If your project requires the use of Sass and vendor prefixes we recommend incorportaing a plugin such as [Autoprefixer](https://github.com/postcss/autoprefixer) into your build process.
|
197 |
|
198 | #### JavaScript
|
199 | `require('uswds')` will load all of the U.S. Web Design System’s JavaScript onto the page. Add this line to whatever initializer you use to load JavaScript into your application.
|
200 |
|
201 | ### Use another framework or package manager
|
202 |
|
203 | If you’re using another framework or package manager that doesn’t support `npm`, you can find the source files in this repository and use them in your project. Otherwise, we recommend that you follow the [download instructions](#download). Please note that the core team [isn’t responsible for all frameworks’ implementations](https://github.com/uswds/uswds/issues/877).
|
204 |
|
205 | If you’re interested in maintaining a package that helps us distribute the U.S. Web Design System, the project’s build system can help you create distribution bundles to use in your project. Please read our [contributing guidelines](CONTRIBUTING.md#building-the-project-locally-with--gulp-) to locally build distributions for your framework or package manager.
|
206 |
|
207 |
|
208 | ## CSS architecture
|
209 |
|
210 | * The CSS foundation of this site is built with the **[Sass](https://sass-lang.com)** preprocessor language.
|
211 | * Uses **[Bourbon](http://bourbon.io/)** for its simple and lightweight Sass mixin library, and the **[Neat](http://neat.bourbon.io/)** library for the grid framework. Bourbon and Neat are open-source products from **[thoughtbot](https://thoughtbot.com/)**.
|
212 | * The CSS organization and naming conventions follow **[18F’s CSS Front End Guide](https://frontend.18f.gov/css/)**.
|
213 | * CSS selectors are **prefixed** with `usa` (For example: `.usa-button`). This identifier helps the design system avoid conflicts with other styles on a site which are not part of the U.S. Web Design System.
|
214 | * Uses a **[modified BEM](https://frontend.18f.gov/css/naming/)** approach created by 18F for naming CSS selectors. Objects in CSS are separated by single dashes. Multi-word objects are separated by an underscore (For example: `.usa-button-cool_feature-active`).
|
215 | * Uses **modular CSS** for scalable, modular, and flexible code.
|
216 | * Uses **nesting** when appropriate. Nest minimally with up to two levels of nesting.
|
217 | * Hard-coded magic numbers are avoided and, if necessary, defined in the `core/variables` scss file.
|
218 | * Media queries are built **mobile first**.
|
219 | * **Spacing units** are as much as possible defined as rem or em units so they scale appropriately with text size. Pixels can be used for detail work and should not exceed 5px (For example: 3px borders).
|
220 |
|
221 | **For more information, visit:**
|
222 | [18F’s CSS Front End Guide](https://frontend.18f.gov/css/)
|
223 |
|
224 |
|
225 | ## JS customization
|
226 |
|
227 | **Unfortunately, customizing the JavaScript for the USWDS currently requires NodeJS and a module bundler like Browserify or Webpack. We apologize for this inconvenience, and are working to resolve it in a future release of the Design System.**
|
228 |
|
229 | The JavaScript for the USWDS is separated into components in the same manner as the visual interface which is all initialized with event handlers when the DOM is ready. These components are accessible as CommonJS modules that can be required in other JavaScript files which then must be built for the browser. The components are currently not accessible in the global browser scope, but can be extended to be included by requiring `components` and setting it to a global scope:
|
230 |
|
231 | ```js
|
232 | window.uswds = require('./components');
|
233 | ```
|
234 |
|
235 | Each component has a standardized interface that can be used to extend it further. The components store a HTML class name (e.g. `.usa-accordion-button[aria-controls]`) that's used to link HTML elements with the JS component, so when a component is initialized, it will search through the current HTML DOM finding all elements that match its class and inialize the component JavaScript for those elements. The primary methods each component has are as follows:
|
236 |
|
237 | - `on`: Initialize a component's JavaScript behavior by passing the root element, such as `window.document`.
|
238 | - `off`: The opposite of `on`, de-initializes a component, removing any JavaScript event handlers on the component.
|
239 | - `hide`: Hide the whole component.
|
240 | - `show`: Shows a whole, hidden component.
|
241 | - `toggle`: Toggles the visibility of a component on and off based on the previous state.
|
242 |
|
243 | Some components have additional methods for manipulating specific aspects of them based on what they are and what they do. These can be found in the component's JS file.
|
244 |
|
245 |
|
246 | ## Customization and theming
|
247 |
|
248 | The Design System can be customized to use different typography, colors and grid systems. The easiest way to do this is to use Sass and override the Design System’s global variables. If it isn’t possible to use Sass, do theming by overriding the CSS rules in the Design System set.
|
249 |
|
250 | To start theming through Sass, copy the `core/variables` file into your own project’s Sass folder, changing applicable variable values, and importing it before the WDS. Below is an example of customizing the import of the Design System's all.scss file.
|
251 |
|
252 | ```scss
|
253 | // src/main.scss
|
254 | @import 'path/to/my/scss/files/main/scss/my-custom-vars';
|
255 | @import 'lib/uswds/src/stylesheets/all';
|
256 | ```
|
257 |
|
258 | ```scss
|
259 | // path/to/my/scss/files/main/scss/my-custom_vars.scss
|
260 |
|
261 | // Colors
|
262 | $color-primary: #2c3e50;
|
263 | $color-secondary: #ad2020;
|
264 | $color-secondary-dark: #b0392e;
|
265 |
|
266 | // Typography
|
267 | $font-serif: 'Georgia', 'Times', serif;
|
268 | $h2-font-size: 2rem;
|
269 | $h3-font-size: 1.75rem;
|
270 | $heading-line-height: 1.4;
|
271 |
|
272 | // Grid/breakpoints
|
273 | $small-screen: 540px !default;
|
274 | $medium-screen: 620px !default;
|
275 | $large-screen: 1120px !default;
|
276 | ```
|
277 |
|
278 | ### Set the base asset path (fonts and images)
|
279 | If you copy the USWDS `dist` directory to a folder on your project or your fonts and images are in the same folder, set the location of the directory with `$asset-path: path/to/my/assets/`. The default is set to `$asset-path: ../`. This will be appended to the font and image path variables so you only need to set this variable. You can also set the font and image paths individually:
|
280 |
|
281 | ```
|
282 | $font-path: path/to/my/fonts;
|
283 | $image-path: path/to/my/images;
|
284 | ```
|
285 |
|
286 | NOTE: If you plan on upgrading to newer versions of the Design System in the future, or are not using your own forked version of the Design System, try to avoid making changes in the Design System folder itself. Doing so could make it impossible to upgrade in the future without undoing your custom changes.
|
287 |
|
288 | ### Main variables that can be customized
|
289 | * Colors can be found in the `core/variables` [file, line 35](https://github.com/uswds/uswds/blob/develop/src/stylesheets/core/_variables.scss#L35).
|
290 | * Font families can be found in the `core/variables` [file, line 28](https://github.com/uswds/uswds/blob/develop/src/stylesheets/core/_variables.scss#L28).
|
291 | * Typography sizing can be found in `core/variables` [file, line 13](https://github.com/uswds/uswds/blob/develop/src/stylesheets/core/_variables.scss#L13).
|
292 | * Grid and breakpoint settings can be found in `core/variables` [file, line 87](https://github.com/uswds/uswds/blob/develop/src/stylesheets/core/_variables.scss#L87).
|
293 |
|
294 |
|
295 | ## Where things live
|
296 |
|
297 | * **HTML** markup for the components is located in: `src/html` in the site root.
|
298 | * **Sass** styles are located in: `src/stylesheets/ (/core, /elements, /components)`. **Compiled CSS** is located in the [downloadable zip file](https://github.com/uswds/uswds/releases/latest).
|
299 | * **JS** is located in: `src/js/components (accordion.js, toggle-field-mark.js, toggle-form-input.js, validator.js)`.
|
300 | * **Fonts** are located in: `src/fonts`.
|
301 | * **Images** and icons are located in: `src/img`.
|
302 |
|
303 |
|
304 | ## Browser support
|
305 |
|
306 | We’ve designed the Design System to support older and newer browsers through [progressive enhancement](https://en.wikipedia.org/wiki/Progressive_enhancement). The current major version of the Design System (1.0) is designed to support the newest versions of Chrome, Firefox, Safari, and Internet Explorer 9 and up. The next major release (2.0) will follow the [2% rule](https://gds.blog.gov.uk/2012/01/25/support-for-browsers/): we will officially support any browser above 2% usage as observed by [analytics.usa.gov](https://analytics.usa.gov/). Currently, this means that the Design System version 2.0 will support the newest versions of Chrome, Firefox, Safari, and Internet Explorer 11 and up.
|
307 |
|
308 |
|
309 | ## Accessibility
|
310 |
|
311 | The Design System also meets the [WCAG 2.0 AA accessibility guidelines](https://www.w3.org/TR/WCAG20/) and conforms to the standards of [Section 508 of the Rehabilitation Act](http://www.section508.gov/). We’re happy to answer questions about accessibility — email us for more information.
|
312 |
|
313 |
|
314 | ## Fractal
|
315 |
|
316 | We're using [Fractal](http://fractal.build) to generate an interactive component library for the Design System. You can run it locally after `npm install` with:
|
317 |
|
318 | ```sh
|
319 | npm start
|
320 | ```
|
321 |
|
322 | Then, visit [http://localhost:3000/](http://localhost:3000/) to see the Design System in action.
|
323 |
|
324 | _**Optional**: To re-build when code changes are made, run the following command from the project directory in a separate terminal window:_
|
325 | ```sh
|
326 | npm run watch
|
327 | ```
|
328 |
|
329 | ### Template compatibility
|
330 |
|
331 | Many of our Fractal view templates are compatible with [Nunjucks](https://mozilla.github.io/nunjucks/) (for JavaScript/Node), [Jinja](http://jinja.pocoo.org/docs/2.9/) (Python), and [Twig](https://twig.sensiolabs.org/) (PHP) out of the box. Components that reference other components use a Fractal-specific `{% render %}` tag that will either need to be implemented in other environments or replaced with the appropriate `{% include %}` tags.
|
332 |
|
333 |
|
334 | ## Need installation help?
|
335 |
|
336 | Do you have questions or need help with setup? Did you run into any weird errors while following these instructions? Feel free to open an issue here:
|
337 |
|
338 | [https://github.com/uswds/uswds/issues](https://github.com/uswds/uswds/issues).
|
339 |
|
340 | You can also email us directly at uswds@gsa.gov.
|
341 |
|
342 |
|
343 | ## Contributing to the code base
|
344 |
|
345 | For complete instructions on how to contribute code, please read [CONTRIBUTING.md](CONTRIBUTING.md). These instructions also include guidance on how to set up your own copy of the Design System style guide website for development.
|
346 |
|
347 | If you would like to learn more about our workflow process, check out the [Workflow](https://github.com/uswds/uswds/wiki/Workflow) and [Issue label Glossary](https://github.com/uswds/uswds/wiki/Issue-label-glossary) pages on the wiki.
|
348 |
|
349 | If you have questions or concerns about our contributing workflow, please contact us by [filing a GitHub issue](https://github.com/uswds/uswds/issues) or [emailing our team](mailto:uswebdesignstandards@gsa.gov).
|
350 |
|
351 |
|
352 | ## Reuse of open-source style guides
|
353 |
|
354 | Much of the guidance in the U.S. Web Design System leans on open source designs, code, and patterns from other civic and government organizations, including:
|
355 |
|
356 | * Consumer Financial Protection Bureau’s [Design Manual](https://cfpb.github.io/design-manual/)
|
357 | * U.S. Patent and Trademark Office’s [Design Patterns](http://uspto.github.io/designpatterns/)
|
358 | * Healthcare.gov [Style Guide](http://styleguide.healthcare.gov/)
|
359 | * UK’s Government Digital Service’s [UI Elements](http://govuk-elements.herokuapp.com/)
|
360 | * Code for America’s Chime [Styleguide](https://github.com/chimecms/chime-starter)
|
361 | * Pivotal Labs [Component Library](http://styleguide.cfapps.io/)
|
362 |
|
363 |
|
364 | ## Licenses and attribution
|
365 |
|
366 | A few parts of this project are not in the public domain. Attribution and licensing information for those parts are described in detail in [LICENSE.md](LICENSE.md).
|
367 |
|
368 | The rest of this project is in the worldwide public domain, released under the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
|
369 |
|
370 |
|
371 | ## Contributing
|
372 |
|
373 | All contributions to this project will be released under the CC0 dedication alongside the public domain portions of this project. For more information, see [CONTRIBUTING.md](CONTRIBUTING.md).
|