Buttons

Buttons are action elements, they allow users to interact with the product. They can be of different sizes, colors and status.

Example

The primary button is plain with a background. For the secondary button, the design system provides a second type of button called outline.

<button type="button" class="nj-btn nj-btn--primary">Primary button</button>
<button type="button" class="nj-btn nj-btn--outline-primary">Secondary button</button>

Color variation

Fluid Design System includes several predefined button styles, each serving its own semantic purpose according to the theme colors palette.

<button type="button" class="nj-btn nj-btn--primary">Primary</button>
<button type="button" class="nj-btn nj-btn--success">Success</button>
<button type="button" class="nj-btn nj-btn--danger">Danger</button>
<button type="button" class="nj-btn nj-btn--warning">Warning</button>
<button type="button" class="nj-btn nj-btn--outline-primary">Primary</button>
<button type="button" class="nj-btn nj-btn--outline-success">Success</button>
<button type="button" class="nj-btn nj-btn--outline-danger">Danger</button>
<button type="button" class="nj-btn nj-btn--outline-warning">Warning</button>
<div class="p-3 bg-blue-corporate">
  <button type="button" class="nj-btn nj-btn--light">Light button</button>
  <button type="button" class="nj-btn nj-btn--outline-light">Outline light button</button>
</div>

Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .sr-only class.

Size variation

Fancy larger or smaller buttons? Add .nj-btn--lg or .nj-btn--sm for additional sizes.

<button type="button" class="nj-btn nj-btn--primary nj-btn--sm">Small button</button>
<button type="button" class="nj-btn nj-btn--primary">Medium button</button>
<button type="button" class="nj-btn nj-btn--primary nj-btn--lg">Large button</button>

Create block level buttons—those that span the full width of a parent—by adding .nj-btn--block.

<button type="button" class="nj-btn nj-btn--primary nj-btn--block">Block level button</button>
<button type="button" class="nj-btn nj-btn--outline-primary nj-btn--block">Block level button</button>

Button tags

The .nj-btn classes are designed to be used with the <button> element. However, you can also use these classes on <a> or <input> elements (though some browsers may apply a slightly different rendering).

When using button classes on <a> elements that are used to trigger in-page functionality (like collapsing content), rather than linking to new pages or sections within the current page, these links should be given a role="button" to appropriately convey their purpose to assistive technologies such as screen readers.

Link
<a class="nj-btn nj-btn--primary" href="#" role="button">Link</a>
<button class="nj-btn nj-btn--primary" type="submit">Button</button>
<input class="nj-btn nj-btn--primary" type="button" value="Input">
<input class="nj-btn nj-btn--primary" type="submit" value="Submit">
<input class="nj-btn nj-btn--primary" type="reset" value="Reset">

Buttons with text and icon

You can add an icon only after the text (on the right).

<a href="#" class="nj-btn nj-btn--primary">Button<i class="nj-btn__icon material-icons">chevron_right</i></a>
<a href="#" class="nj-btn nj-btn--primary "><i class="nj-btn__icon nj-btn__icon--before material-icons ">add</i>Button</a>
<a href="#" class="nj-btn nj-btn--outline-primary nj-btn--lg">Button<i class="nj-btn__icon material-icons md--blue-corporate">get_app</i></a>
<a href="#" class="nj-btn nj-btn--danger nj-btn--sm"><i class="nj-btn__icon nj-btn__icon--before material-icons">close</i>Button</a>

Buttons with only one icon

<a href="#" class="nj-btn nj-btn--primary nj-btn--icon nj-btn--sm"><i class="material-icons">add</i></a>
<a href="#" class="nj-btn nj-btn--primary nj-btn--icon"><i class="material-icons">add</i></a>
<a href="#" class="nj-btn nj-btn--primary nj-btn--icon nj-btn--lg"><i class="material-icons">add</i></a>

Active state

Buttons will appear pressed (with a darker background, darker border, and inset shadow) when active. There’s no need to add a class to <button>s as they use a pseudo-class. However, you can still force the same active appearance with .active (and include the aria-pressed="true" attribute) should you need to replicate the state programmatically.

<a href="#" class="nj-btn nj-btn--primary active" role="button" aria-pressed="true">Primary link</a>
<a href="#" class="nj-btn nj-btn--outline-primary active" role="button" aria-pressed="true">Link</a>

Disabled state

Make buttons look inactive by adding the disabled boolean attribute to any <button> element.

<button type="button" class="nj-btn nj-btn--primary" disabled>Primary button</button>
<button type="button" class="nj-btn nj-btn--danger" disabled>Button with icon<i class="nj-btn__icon material-icons md--white">chevron_right</i></button>

Disabled buttons using the <a> element behave a bit different:

  • <a>s don’t support the disabled attribute, so you must add the .disabled class to make it visually appear disabled.
  • Some future-friendly styles are included to disable all pointer-events on anchor buttons. In browsers which support that property, you won’t see the disabled cursor at all.
  • Disabled buttons should include the aria-disabled="true" attribute to indicate the state of the element to assistive technologies.
<a href="#" class="nj-btn nj-btn--primary disabled" role="button" aria-disabled="true">Primary link</a>

The .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, but that CSS property is not yet standardized. In addition, even in browsers that do support pointer-events: none, keyboard navigation remains unaffected, meaning that sighted keyboard users and users of assistive technologies will still be able to activate these links. So to be safe, add a tabindex="-1" attribute on these links (to prevent them from receiving keyboard focus) and use custom JavaScript to disable their functionality.