We use the VA Design System, aka "Formation", as our base library for styling the site. VADS is composed of the formation
and formation-react
packages, which provide SASS styles and React components, respectively.
If you have questions about any of the guidelines in this document, please feel free to reach out in #ao-engineering. You can also post in the #sparklemotion channel, as Sparklemotion are currently the domain experts for the developer portal.
- The VA Design System
- Developer Portal Custom Styles
- Checklist for Wriing Components and Styles
- Resources
Broadly speaking, the formation
styles come in 3 types: components, layouts, and utilities. Components are used to style specific pieces of site functionality. Layout styles implement a flexbox grid system for spacing components on the page. (Please do not use the legacy float grid.) Utilities are classes that provide specific CSS property values, such as margin
or color
. Utility classes use !important
to override any other selectors that might apply to that element, so utility classes can be assumed to be authoritative and should take precedence over other styles. The combination of these three types of classes greatly reduces the amount of SCSS that we need to write on our own. VADS styling should always take precedence over classes we write ourselves; we should aim to style all of our components in JSX using the VADS to the extent possible.
VADS classes use Block, Element, Modifier (BEM) syntax as a naming convention. All classes (at least, those with up-to-date names) are prefixed with vads-(c|l|u)-
, where c
, l
, and u
refer to components, layouts, and utilities, respectively.
The following table documents the formation
styles that we use in the developer portal (excluding VADS utilities, which are ubiquitous, and USWDS classes).
formation CSS class |
Purpose | Defined in source file | Consumed in |
---|---|---|---|
feature |
Calls attention to important blocks of text | _va.scss |
ApplyForm |
form-checkbox |
Provides checkbox form styles | _m-form-elements.scss |
ApplyForm , Beta (to be deprecated) |
va-crisis-line |
Top-level class for the Veterans Crisis Line (VCL) container | _m-crisis-line.scss |
VeteransCrisisLine |
va-crisis-line-button |
Styles the VCL button | _m-crisis-line.scss |
VeteransCrisisLine |
va-crisis-panel |
Container class for the VCL modal contents | _m-crisis-line.scss |
VeteransCrisisLinePanel |
va-crisis-panel-body |
Styles the inside of the VCL modal | _m-crisis-line.scss |
VeteransCrisisLinePanel |
vcl |
Styles the white VCL flag icon on the left of the VCL button | _m-crisis-line.scss |
VeteransCrisisLine |
uswds
, the npm
package for the US Web Design System, is a direct dependency of formation
, and formation
exports some parts of uswds
as part of its library. As a result, we use some USWDS styles on the developer portal. Most, if not all, of these styles are documented in the VADS component docs. We should only use USWDS styles that are exported and documented by VADS.
Component Type | uswds CSS classes |
Purpose | Defined in source file | Documentation |
---|---|---|---|---|
Accordion | usa-accordion , usa-accordion-button , usa-accordion-content |
Handles display of expandable/collapsible content | _accordions.scss |
https://design.va.gov/components/accordions |
Alert | usa-alert , usa-alert-heading , usa-alert-body , usa-alert-info , usa-alert-warning , usa-alert-error , usa-alert-success , usa-alert-continue |
Displaying info to the user | _alerts.scss |
https://design.va.gov/components/alertboxes |
Button | usa-button , usa-button-primary , usa-button-secondary , usa-button-active , usa-button-hover , usa-button-big , usa-button-disabled |
Provide styles for button elements | _buttons.scss |
https://design.va.gov/components/buttons |
Form | usa-form |
Sets some basic form properties | _forms.scss |
https://design.va.gov/components/form-controls |
Label | usa-label |
Standard label styles | _labels.scss |
https://design.va.gov/components/labels |
Sidenav | usa-sidenav-list |
Provides some styles for lists of items within the side nav | _sidenav.scss |
https://design.va.gov/components/sidenav |
The following list documents all of the USWDS classes we currently use.
uswds CSS class |
Consumed in |
---|---|
usa-accordion-content |
Banner , formation-react 's CollapsiblePanel in GroupedAccordions |
usa-alert |
Deprecation notice in ApiPage |
usa-alert-body |
Deprecation notice in ApiPage |
usa-alert-info |
Deprecation notice in ApiPage |
usa-button |
Various places: Hero , NavBar , Header , ApplyForm , SupportContactUs |
usa-button-primary |
Form , ApplyForm |
usa-font-lead |
ApplyHeader , ApplySuccess (NOT DOCUMENTED, probably don't use again) |
usa-form |
ApplyForm , swaggerPlugins/Servers |
usa-sidenav-list |
SideNav |
The following list covers the CSS properties for which there are available utilities. For these properties, you should always prefer VADS utilities unless there is a specific reason that you cannot use them. For some common cases where VADS utilities will not work, see Known Gaps.
- Background color
- Border
- Color
- Display
- Flexbox
- Flex parent:
flex-direction
,flex-wrap
,align-items
,justify-content
,align-content
- Flex child:
flex-grow
,order
- Flex parent:
- Font family
- Font size
- Font style
- Font weight
- Height and width
- Line height
- Margins
- Padding
- Text align
- Text decoration
- Visibility
Note that some of these utilities use the responsive breakpoints (medium-screen:[utility]
, etc) and others do not.
There are a few consistently identifiable gaps in VADS that require us to write our own styles either as our own utility classes or in component stylesheets. These are areas where, if we are able to develop utilities following the VADS pattern to supplement the actual VADS utilities, we may be able to push changes upstream to formation
. In any case, you can be confident that you will need to write or use developer portal-specific styles for these cases.
- Colors of any kind (
background-color
,border-color
) are not responsive. We have some elements (e.g., the search box) that use different colors on mobile and desktop. - There aren't utilities to help with DOM events such as
focus
,hover
, etc (to my knowledge as of this writing). - Miscellaneous lesser-used properties:
cursor
,text-transform
,list-style
- It is difficult to style elements when a parent-child relationship is relevant to the style logic. (To be fair, this would be a difficult problem to address generically. You can be confident in writing component-specific styles in this case.)
- One specific case of this situation is when styling third-party components. In this case, the pattern that we have to follow to style these components is
[.top-level-component-class] [element-tag-to-style] { ... }
. Since we don't ever have access to the element we want to style, we need to write a custom stylesheet; VADS utilities will never be useful in this case. Given that fact, the goal for these stylesheets should be to make them less opaque and easier to reason about in a way that complements the rest of our CSS approach. The current examples of this pattern aresrc/styles/swagger.scss
forswagger-ui
andsrc/styles/tabs.scss
forreact-tabs
.
- One specific case of this situation is when styling third-party components. In this case, the pattern that we have to follow to style these components is
- The width and height utilities generally don't offer options other than
0
,100%
, andauto
.
formation-react
is the React package of VADS. See here for documentation on available components.
TODO
If you do need to write custom styles, please namespace all of your classes with va-api-
. This pattern will allow us to identify which classes we need to maintain in future refactors of the developer portal styles and to identify patterns in our CSS needs that can be abstracted site-wide.
As documented above, there are some gaps in VADS that could benefit from similar utilities to the ones exported by formation
. If you have a generalizable style that could be extracted into a similar utility, feel free to add it to src/styles/lib.scss
. There are some examples already in that file that can be used as a guide.
- Check
formation-react
to see if there is a React component that meets your needs. - Check the
formation
component docs to see if there are component styles that can be a useful starting point for writing your component. - Try to write the component using the VADS utilities.
- See if there are any Lighthouse developer portal utilities in
src/styles/lib.scss
that can help with functionality not provided by theformation
utilities. - Add a utility of the form
va-api-u-[css-property]--[value]
tolib.scss
if the functionality you need can be generalized but is not already included information
orlib.scss
. - Write a custom component stylesheet that covers anything that can't be accomplished by any of the above strategies.
Related resources:
- VADS components
- VADS layout
- VADS utilities
formation-react
docs- VADS naming conventions
- SASS language documentation
- Bourbon framework docs (Bourbon is the base library for
uswds
)bourbon-neat
v1.8.0 docs (note thatbourbon-neat
is unmaintained)bourbon
v4 docs (current version is6.0.0
,uswds
is on4.2.7
)
veteran-facing-services-tools
, the monorepo forformation
andformation-react
uswds