Button • Natura11y
Brown mushrooms on ground

Photo by Karl Anderson

Button

Introduction

Create distinct, actionable buttons with options for icons and customization. Explore various designs, colors, and sizes to ensure a great user experience and accessibility.


Using Buttons

To use buttons in Natura11y, add a .button class to an <a> or <button> tag. By default, buttons will inherit the text color and font size of their parent element.

Here's a basic button example with no extra styles.


        <!-- Link styled as a button -->
        <a class="button" href="#1">
            Button
        </a>
        
        <!-- Button element -->
        <button class="button">
            Button
        </button>

        <!-- Link styled as a button with text inside optional span -->
        <a class="button" href="#1">
            👉 <span class="text">Button</span>
        </a>
    
Figure 1
Line #Details
2

The parent .button selector is required. This selector provides the button's default styles.

13

Optionally, you can wrap the button text in a <span class="text"> tag. This will automatically create an underline when the button is hovered over or focused on.


Coloring Buttons

Add color to a .button selector with our theme color utilities. These classes apply the button's appropriate text color automatically (Figure 2).


        <a class="button 👉 theme-primary" href="#1">
            Button
        </a>
        
        <a class="button 👉 theme-secondary" href="#1">
            Button
        </a>
        
        <a class="button 👉 theme-dark" href="#1">
            Button
        </a>
    
Figure 2

Full-width Buttons

For buttons that span the width of their parent, add the .width-100 size utility class (Figure 3).


        <a class="button theme-primary 👉 width-100" href="#1">
            Button
        </a>
    
Figure 3

Do not use .display-block for full-width buttons. Buttons have a display property of flex (for vertical centering text with icons). Using use .display-block changes the buttons display property from flex to block. This breaks the vertical centering of the icon within the button (See buttons with text and icon below).


Outlined Buttons

Create a button with an outline instead of a fill. Add the outline modifier class .button--outline to the .button selector. The outline width is a 2x multiple of your theme's body border width.

The outline color inherits the button's text color. You can change the color using our text color utility classes.


        <a class="button 👉 button--outline" href="#1">
            Button
        </a>
        
        <a class="button 👉 button--outline text-color-link" href="#1">
            Button
        </a>
    
Figure 4

Button Border Radius

Globally, all .button selectors have a border radius. This value is set with the :root scoped CSS Variable --button-border-radius (see Figure 5). Learn how to customize CSS Variables.


        /* Globally remove border radius in CSS */
        
        :root {
            --button-border-radius: 0;
        }
    
Figure 5

Optionally, use our border-radius utility classes (e.g. .border-radius-pill) on .button selectors.


        <a class="button theme-primary 👉 border-radius-pill" href="#1">
            Button
        </a>
    
Figure 6

Sizing Buttons

With Natura11y, .button selectors inherit their font size. Padding is set with relative (em) sizes. This allows you to resize multiple buttons at once. Use our font size utility classes, or declare your own CSS values.

The example below applies the .font-size-sm utility class to a <ul> containing buttons. Each button within this <ul> becomes smaller with this single declaration.


        <ul class="nav nav--horizontal 👉 font-size-sm">
            <li>
                <a class="button" href="#1">
                    Button
                </a>
            </li>
            <li>
                <a class="button" href="#1">
                    Button
                </a>
            </li>
            <li>
                <a class="button" href="#1">
                    Button
                </a>
            </li>
        </ul>
    
Figure 7

Text and Icon Buttons

To include an icon in a button, add the appropriate <span> with its combined icon classes as a child of the .button element (Figure 8). Icons can go before the text, after the text, or both, depending on your design needs.


        <a class="button theme-primary" href="#1">
            <span class="icon icon-edit"></span> 👈
            <span class="text">Button</span>
        </a>
        
        <a class="button button--outline" href="#1">
            <span class="icon icon-delete"></span> 👈
            <span class="text">Delete</span>
        </a>
    
Figure 8

Dispersing the text and icon

Create a button where the text and icon sit on opposing sides. Add the chain modifier class --disperse to .button class. Chained together, the full class is .button--disperse. By default, this class makes the button full-width of its parent.


        <a class="button button--disperse 👈 text-color-link" href="#1">
            <span class="button__text">Button</span>
            <span class="icon icon-arrow-right"></span>
        </a>
    
Figure 9

Icon-only Buttons

For icon-only buttons, apply the .button--icon--only modifier class to the .button selector.

Icon-only buttons require a single child selector. A <span> with its combined icon classes (just like the text and icon buttons described above).


        <a class="button button--icon-only" href="#1" aria-label="Home">
            <span class="icon icon-home" aria-hidden="true"></span>
        </a>
    
Figure 10

Icon-only buttons are transparent by default. Like our other buttons, color can be applied with background-color and text color utility classes.


        <a class="button button--icon-only 👉 theme-primary" href="#1" aria-label="Home">
            <span class="icon icon-home" aria-hidden="true"></span>
        </a>
    
Figure 11

Do not use the title attribute to describe the button(on its hover state). Instead apply the aria-label attribute (see Figure 10). Icon-only buttons with the aria-label attribute offer a custom visible tooltip. The core javascript file (natura11y.js) adds these tooltips to the DOM when the document loads.


Icon Over Text Buttons

Position a prominent icon over smaller text. To do this, append the .button--icon-over-text modifier class to a .button selector. This button arrangement, inclusive of both the text and the icon, has a fixed width which you can customize to suit your needs. By allowing the text to be marginally broader than the icon, the text can extend to a new line when it exceeds the available width.


        <button class="button 👉 button--icon-over-text">
            <span class="button__icon">
                <span class="icon icon-search" aria-hidden="true"></span>
            </span>
            <span class="button__text">Home</span>
        </button>
    
Figure 12

Customize .button--icon-over-text buttons With relevant CSS variables or utility classes.


        <button class="button 👉 button--icon-over-text">
            <span class="button__icon 👉 theme-primary border-radius-circle">
                <span class="icon icon-search" aria-hidden="true"></span>
            </span>
            <span class="button__text 👉 text-color-primary">Home</span>
        </button>
    
Figure 13