Import

import NProgress, { createProgress, defaultSettings, injectStyles, version } from 'nprogress-next'
import 'nprogress-next/styles.css' // optional

Singleton: NProgress

The default export is a ready-to-use singleton, API-compatible with NProgress 0.2.0.

import NProgress from 'nprogress-next'

NProgress.start()
NProgress.set(0.5)
NProgress.inc()
NProgress.done()

createProgress(options?)

Creates an isolated instance. Use when you need multiple independent progress bars.

import { createProgress } from 'nprogress-next'

const uploadProgress = createProgress({ minimum: 0.1, trickle: false })
const downloadProgress = createProgress({ parent: '#download-area' })

uploadProgress.start()
downloadProgress.start()

Options (ProgressOptions)

All options are optional. Pass to createProgress() or NProgress.configure().

OptionTypeDefaultDescription
minimumnumber0.08Minimum progress shown on start
easingstring'ease'CSS easing for bar transition
speednumber200Transition duration in ms
tricklebooleantrueAuto-advance while visible
trickleRatenumber0.02Max fraction per trickle step (0.2.0 compat)
trickleSpeednumber800Interval between trickle steps (ms)
showSpinnerbooleantrueRender the corner spinner
barSelectorstring'[role="bar"], .bar'Selector for bar element in template
spinnerSelectorstring'[role="spinner"], .spinner'Selector for spinner element
parentstring | HTMLElement'body'Where to mount the bar
templatestringsee belowHTML template for the bar
idstring'nprogress'DOM id for the container
ariaLabelstring | null'Loading'Accessible label (null to omit)
autoInjectStylesbooleantrueInject default stylesheet on first render
respectReducedMotionbooleantrueRespect prefers-reduced-motion
positionUsingstring'translate'Positioning method (0.2.0 compat)

Default Template

const DEFAULT_TEMPLATE = `
  <div class="bar" role="bar" aria-hidden="true">
    <div class="peg"></div>
  </div>
  <div class="spinner" role="spinner" aria-hidden="true">
    <div class="spinner-icon"></div>
  </div>
`

Methods

MethodReturnsDescription
start()ProgressInstanceShow bar at minimum, begin trickle loop
done(force?)ProgressInstanceComplete & hide. force=true shows even if not started
set(n)ProgressInstanceSet progress 0..1 (clamped to minimum..1)
inc(amount?)ProgressInstanceIncrement by amount or smart default (0.2.0 formula)
trickle()ProgressInstanceAlias for inc(Math.random() * trickleRate)
configure(opts)ProgressInstanceMerge options into settings
promise(p)ProgressInstanceTrack promise(s); done when all settle
render(fromStart?)HTMLElement | nullRender container (internal)
remove()voidRemove container & cleanup
isStarted()booleanWhether progress is active
isRendered()booleanWhether container is in DOM
getPositioningCSS()stringCSS for bar positioning (0.2.0 compat)

Events: subscribe(listener)

Subscribe to status changes. Returns an unsubscribe function.

const unsubscribe = NProgress.subscribe((status) => {
  console.log('Progress:', status) // number 0..1 or null
})

// Later
unsubscribe()

Properties

PropertyTypeDescription
statusnumber | nullCurrent progress 0..1 or null when idle. Writable (0.2.0 compat).
settingsProgressSettingsLive settings object. Mutate via configure().
versionstringPackage version (e.g. '0.1.0')

Utilities

import { defaultSettings, injectStyles, version } from 'nprogress-next'

// Default settings object (clone before mutating)
const mySettings = { ...defaultSettings, color: '#f00' }

// Manually inject styles (if autoInjectStyles: false)
injectStyles()

// Version string
console.log(version) // '0.1.0'

SSR Safety

All imports and method calls are safe in Node/SSR environments — no window/document access until render() is actually called.