BASE

barba.js

barba.js

Development library / tool · Free

Page transitions for conventional websites without a full reload: it replaces the content container and lets you coordinate navigation animations.

Also known as: barbajs/barba

Resource illustration: barba.js

Open resource ↗

What you can use for free

barba.js code is available free of charge for local and commercial projects, subject to its license.

Paid features and costs

This library does not require a paid plan. Development and hosting of the finished application are separate from the free code license.

Access and limitations

barba.js code is available free of charge for local and commercial projects, subject to its license. This library does not require a paid plan. Development and hosting of the finished application are separate from the free code license.

Use cases

  • UI or SVG animation
  • Smooth website content transitions
  • Coordinate content exit and entry animations when navigating between pages
  • Replace the page container without fully reloading a conventional website

Example workflow

A possible workflow; this is not a report of hands-on testing.

UI or SVG animation with barba.js.

Before you start

  • A working JavaScript; DOM project and a specific use case: UI or SVG animation.
  • A design, interface states, or dataset; target screens and accessibility requirements.

Steps

  1. Check the project's stack and version against the current barba.js documentation; add the package or the required source component. For page transitions, prepare a wrapper and nested container on each page; use namespace to select transition rules and Views.
  2. Implement the selected workflow using the provided data, adapting styles and states to the project. Align the old container's exit and the new container's entry with the lifecycle. If animating SVG or other elements, check their separate initialization after navigation.
  3. Check the result in the target environment, remove demo data, and retain notices required by the license. One possible check is several transitions back and forth, correct body classes, functioning forms and widgets, and no accumulated listeners or ScrollTrigger instances.

Check your result

  • The example works in the chosen tech stack, including target dimensions and input errors.
  • Dependency size, keyboard behavior, and reduced motion suit the task; license terms are met.

Choosing barba.js

UI or SVG animation

Choose this when

  • UI or SVG animation
  • Smooth website content transitions
  • Coordinate content exit and entry animations when navigating between pages

Consider alternatives when

  • When choosing for this topic, compare barba.js with Moti. A candidate to compare: both product pages list the use case “UI or SVG animation”. Implementation approach and compatibility are checked separately.
  • When choosing for this topic, compare barba.js with Rough Notation. A candidate to compare: both product pages list the use case “UI or SVG animation”. Implementation approach and compatibility are checked separately.

Requirements

  • Prepared wrapper/container HTML markup; the guide assumes knowledge of HTML, CSS, and JavaScript.

Things to consider

  • Costs and limits of free use: This library does not require a paid plan. Development and hosting of the finished application are separate from the free code license.
  • Terms of use: MIT: permits free commercial use, modification, and distribution of the code, with the license text and copyright notice retained. The code is provided without warranties; check third-party widget and service terms separately.
  • Inline scripts do not restart automatically after a page change through Barba.

Frequently asked questions

What can you use for free in barba.js?

barba.js code is available free of charge for local and commercial projects, subject to its license.

What additional costs might arise with barba.js?

This library does not require a paid plan. Development and hosting of the finished application are separate from the free code license.

What terms of use matter for barba.js?

MIT: permits free commercial use, modification, and distribution of the code, with the license text and copyright notice retained. The code is provided without warranties; check third-party widget and service terms separately.

How do you get started with barba.js?

Check the project's stack and version against the current barba.js documentation; add the package or the required source component. For page transitions, prepare a wrapper and nested container on each page; use namespace to select transition rules and Views. Implement the selected workflow using the provided data, adapting styles and states to the project. Align the old container's exit and the new container's entry with the lifecycle. If animating SVG or other elements, check their separate initialization after navigation. Check the result in the target environment, remove demo data, and retain notices required by the license. One possible check is several transitions back and forth, correct body classes, functioning forms and widgets, and no accumulated listeners or ScrollTrigger instances.

How do I prepare markup for barba.js?

Content to be replaced is placed in data-barba="container" inside data-barba="wrapper". Elements outside the container are not replaced; namespace helps select transitions and Views.

What happens to scripts after a transition?

The documentation warns that inline scripts do not execute again during Barba navigation. Third-party widget integration and cleanup of previous instances must use lifecycle hooks or Views.

Why does the header or footer not change after a transition?

Barba updates the container, while elements inside the wrapper but outside the container remain unchanged. If part of the header, navigation, or footer must change with the page, the documentation recommends placing it in the replaced container; the wrapper must encompass the container.

Why do scroll effects accumulate after several transitions?

The documentation warns about repeated ScrollTrigger instances and shows creating them on entry through Views and cleaning them up after exit. One possible check is to align each widget's creation and destruction with the lifecycle and avoid duplicating global handlers.

Are WordPress body classes updated automatically?

If body is outside the replaced container, its classes remain. For WordPress, the guide shows manually updating classes from next.html and asks users to adapt the example to their needs. This is a separate integration task that must be checked across all page templates.

Related tasks and approaches

  • Moti

    A candidate to compare: both product pages list the use case “UI or SVG animation”. Implementation approach and compatibility are checked separately.

  • Rough Notation

    A candidate to compare: both product pages list the use case “UI or SVG animation”. Implementation approach and compatibility are checked separately.

  • tsParticles

    A candidate to compare: both product pages list the use case “UI or SVG animation”. Implementation approach and compatibility are checked separately.

License

MIT: permits free commercial use, modification, and distribution of the code, with the license text and copyright notice retained. The code is provided without warranties; check third-party widget and service terms separately.

MIT — permissive license

You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.

License terms

Technologies and topics

  • JavaScript
  • DOM
  • web

Sources

Other resources