Ripple

Ripples are visual representations used to communicate the status of a component or interactive element.

Installation

We use @material/ripple for Ripple effects, which can be used from a CDN or installed using a package manager.


  1. CDN
<!-- MDC Ripple JS -->
<script src="https://unpkg.com/@material/ripple@14.0.0/dist/mdc.ripple.min.js"
        integrity="sha384-9QANVmWxL3S8VRs8x1Q+bF1Zzogpy7P/Qw1+y5qHLdC1ig0EuoHg9VbB1SXyecdZ"
        crossorigin="anonymous"></script>

  1. NPM
npm i @material/ripple@14.0.0

Add Ripple effect

To add Ripple to your component:

  1. Add Ripple surface (<span class="ripple-surface"></span>) to your component.
  2. Set the position of your component to either relative, absolute, fixed, or sticky (In other words, anything except static), since a Ripple surface is absolute positioned.
  3. Initialize the Ripple surface with Javascript to get the Ripple effect.
This component requires Javascript for initialization. Click to view Javascript.

On Buttons

html
<button type="button" class="btn btn-success m-1">
  Success | Green
  <span class="ripple-surface"></span>
</button>
html
<button type="button" class="btn btn-warning m-1">
  Warning | Yellow
  <span class="ripple-surface"></span>
</button>
html
<button type="button" class="btn btn-outline-purple m-1">
  Outlined Button
  <span class="ripple-surface"></span>
</button>
html
<button type="button" class="btn btn-outline-pink border-0 m-1">
  Text Button
  <span class="ripple-surface"></span>
</button>
 

On Tabs

Apple
Apricot
Avocado
html
<ul class="nav nav-tabs nav-justified primary-indigo base-pink" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link" data-bs-toggle="tab" role="tab" data-bs-target="#apple">
      Apple
      <span class="ripple-surface"></span>
    </button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link active" data-bs-toggle="tab" role="tab" data-bs-target="#apricot">
      Apricot
      <span class="ripple-surface"></span>
    </button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" data-bs-toggle="tab" role="tab" data-bs-target="#avocado">
      Avocado
      <span class="ripple-surface"></span>
    </button>
  </li>
</ul>
<!-- Tab Panes -->
<div class="tab-content">
  <div class="tab-pane container-fluid fade" role="tabpanel" id="apple">Apple</div>
  <div class="tab-pane container-fluid active" role="tabpanel" id="apricot">Apricot</div>
  <div class="tab-pane container-fluid fade" role="tabpanel" id="avocado">Avocado</div>
</div>

On a div

Ripple on a div
html
<div class="bg-teal p-4 position-relative">
  Ripple on a div
  <span class="ripple-surface"></span>
</div>
 

Color

Use the custom property --mdc-ripple-color to set the color of the Ripple.

Ripple with custom color
html
<div class="bg-white border p-4 position-relative" style="--mdc-ripple-color: blue;">
  Ripple with custom color
  <span class="ripple-surface"></span>
</div>
 

Color levels

Use the custom properties:

  • --mdc-ripple-hover-opacity to set hover color opacity.
  • --mdc-ripple-focus-opacity to set focus color opacity.
  • --mdc-ripple-press-opacity to set active color opacity.
Ripple with custom color
html
<div class="bg-white border p-4 position-relative" 
     style="--mdc-ripple-color: blue; --mdc-ripple-hover-opacity: .3; --mdc-ripple-focus-opacity: .4; --mdc-ripple-press-opacity: .5;">
  Ripple with custom color
  <span class="ripple-surface"></span>
</div>
 

Javascript

If CDN is used to add @material/ripple to the project

// Initialize Ripple
const rippleSurface = Array.prototype.slice.call(document.querySelectorAll('.ripple-surface'))
rippleSurface.map(s => {
  return new mdc.ripple.MDCRipple(s)
})

Else

// Import MDCRipple
import { MDCRipple } from '@material/ripple';

// Initialize Ripple
const rippleSurface = Array.prototype.slice.call(document.querySelectorAll('.ripple-surface'))
rippleSurface.map(s => {
  return new MDCRipple(s)
})
We are aware that the documentation is incomplete. While we work on it, You may refer to Bootstrap docs or help us by contributing.