Number input

Invalid number
Invalid number
Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
Invalid number
Vanilla JS
Code:
<!--
  Copyright IBM Corp. 2016, 2018

  This source code is licensed under the Apache-2.0 license found in the
  LICENSE file in the root directory of this source tree.
-->

<div class="bx--form-item">
  <div data-numberinput class="
    bx--number
    
  ">
    <label for="number-input0" class="bx--label">Number input label</label>
    <div class="bx--number__input-wrapper">
      <input id="number-input0" type="number" min="0" max="100" value="1">
      <div class="bx--number__controls">
        <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
        </button>
        <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
        </button>
      </div>
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-invalid data-numberinput class="
    bx--number
    
  ">
    <label for="number-input1" class="bx--label">Number input label</label>
    <div class="bx--number__input-wrapper">
      <input id="number-input1" type="number" min="0" max="100" value="1" role="alert" aria-atomic="true">
      <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" class="bx--number__invalid" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1C4.2 1 1 4.2 1 8s3.2 7 7 7 7-3.1 7-7-3.1-7-7-7zm-.5 3h1v5h-1V4zm.5 8.2c-.4 0-.8-.4-.8-.8s.3-.8.8-.8c.4 0 .8.4.8.8s-.4.8-.8.8z"></path><path d="M7.5 4h1v5h-1V4zm.5 8.2c-.4 0-.8-.4-.8-.8s.3-.8.8-.8c.4 0 .8.4.8.8s-.4.8-.8.8z" data-icon-path="inner-path" opacity="0"></path></svg>
      <div class="bx--number__controls">
        <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
        </button>
        <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
        </button>
      </div>
    </div>
    <div class="bx--form-requirement">
      Invalid number
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-invalid data-numberinput class="
    bx--number
    
    bx--number--nolabel
  ">
    <div class="bx--number__input-wrapper">
      <input id="number-input2" type="number" min="0" max="100" value="1" role="alert" aria-atomic="true">
      <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" class="bx--number__invalid" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1C4.2 1 1 4.2 1 8s3.2 7 7 7 7-3.1 7-7-3.1-7-7-7zm-.5 3h1v5h-1V4zm.5 8.2c-.4 0-.8-.4-.8-.8s.3-.8.8-.8c.4 0 .8.4.8.8s-.4.8-.8.8z"></path><path d="M7.5 4h1v5h-1V4zm.5 8.2c-.4 0-.8-.4-.8-.8s.3-.8.8-.8c.4 0 .8.4.8.8s-.4.8-.8.8z" data-icon-path="inner-path" opacity="0"></path></svg>
      <div class="bx--number__controls">
        <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
        </button>
        <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
        </button>
      </div>
    </div>
    <div class="bx--form-requirement">
      Invalid number
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-numberinput class="
    bx--number
    
    bx--number--helpertext
  ">
    <label for="number-input3" class="bx--label">Number input label</label>
    <div class="bx--form__helper-text">
      Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
    </div>
    <div class="bx--number__input-wrapper">
      <input id="number-input3" type="number" min="0" max="100" value="1">
      <div class="bx--number__controls">
        <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
        </button>
        <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
        </button>
      </div>
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-invalid data-numberinput class="
    bx--number
    
    bx--number--helpertext
  ">
    <label for="number-input4" class="bx--label">Number input label</label>
    <div class="bx--form__helper-text">
      Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
    </div>
    <div class="bx--number__input-wrapper">
      <input id="number-input4" type="number" min="0" max="100" value="1" role="alert" aria-atomic="true">
      <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" class="bx--number__invalid" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1C4.2 1 1 4.2 1 8s3.2 7 7 7 7-3.1 7-7-3.1-7-7-7zm-.5 3h1v5h-1V4zm.5 8.2c-.4 0-.8-.4-.8-.8s.3-.8.8-.8c.4 0 .8.4.8.8s-.4.8-.8.8z"></path><path d="M7.5 4h1v5h-1V4zm.5 8.2c-.4 0-.8-.4-.8-.8s.3-.8.8-.8c.4 0 .8.4.8.8s-.4.8-.8.8z" data-icon-path="inner-path" opacity="0"></path></svg>
      <div class="bx--number__controls">
        <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
        </button>
        <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
          aria-live="polite" aria-atomic="true">
          <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
        </button>
      </div>
    </div>
    <div class="bx--form-requirement">
      Invalid number
    </div>
  </div>
</div>

Number input mobile

Invalid number
Invalid number
Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
Invalid number
Vanilla JS
Code:
<!--
  Copyright IBM Corp. 2016, 2018

  This source code is licensed under the Apache-2.0 license found in the
  LICENSE file in the root directory of this source tree.
-->

<div class="bx--form-item">
  <div data-numberinput class="
    bx--number
    
     bx--number--mobile 
    ">
    <label for="mobile-number-input0" class="bx--label">Number input label</label>
    <div class="bx--number__input-wrapper">
      <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
      </button>
      <input id="mobile-number-input0" type="number" pattern="\d*" min="0" max="100" value="1">
      <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
      </button>
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-invalid data-numberinput class="
    bx--number
    
     bx--number--mobile 
  ">
    <label for="mobile-number-input1" class="bx--label">Number input label</label>
    <div class="bx--number__input-wrapper">
      <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
      </button>
      <input id="mobile-number-input1" type="number" pattern="\d*" min="0" max="100" value="1" role="alert"
        aria-atomic="true">
      <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
      </button>
    </div>
    <div class="bx--form-requirement">
      Invalid number
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-invalid data-numberinput class="
      bx--number
      
       bx--number--mobile 
      bx--number--nolabel
    ">
    <div class="bx--number__input-wrapper">
      <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
      </button>
      <input id="mobile-number-input2" type="number" pattern="\d*" min="0" max="100" value="1" role="alert"
        aria-atomic="true">
      <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
      </button>
    </div>
    <div class="bx--form-requirement">
      Invalid number
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-numberinput class="
    bx--number
    
     bx--number--mobile 
    bx--number--helpertext
  ">
    <label for="mobile-number-input3" class="bx--label">Number input label</label>
    <div class="bx--form__helper-text">
      Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
    </div>
    <div class="bx--number__input-wrapper">
      <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
      </button>
      <input id="mobile-number-input3" type="number" pattern="\d*" min="0" max="100" value="1">
      <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
      </button>
    </div>
  </div>
</div>

<div class="bx--form-item">
  <div data-invalid data-numberinput class="
    bx--number
    
     bx--number--mobile 
    bx--number--helpertext
  ">
    <label for="mobile-number-input4" class="bx--label">Number input label</label>
    <div class="bx--form__helper-text">
      Optional helper text here; if message is more than one line text should wrap (~100 character count maximum)
    </div>
    <div class="bx--number__input-wrapper">
      <button aria-label="decrease number input" class="bx--number__control-btn down-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M8 0L4 4 0 0z"></path></svg>
      </button>
      <input id="mobile-number-input4" type="number" pattern="\d*" min="0" max="100" value="1" role="alert"
        aria-atomic="true">
      <button aria-label="increase number input" class="bx--number__control-btn up-icon" type="button"
        aria-live="polite" aria-atomic="true">
        <svg focusable="false" preserveAspectRatio="xMidYMid meet" style="will-change: transform;" xmlns="http://www.w3.org/2000/svg" width="8" height="4" viewBox="0 0 8 4" aria-hidden="true"><path d="M0 4l4-4 4 4z"></path></svg>
      </button>
    </div>
    <div class="bx--form-requirement">
      Invalid number
    </div>
  </div>
</div>

Documentation

JavaScript

Options

Option Default Selector Description
selectorInit [data-numberinput] The CSS selector to find number input HTML

Events

Name Description
click Increases and decreases value attribute of number-input
change Emitted when click event inceases or decreases number-input value