Read the Docs tutorial for Docusaurus
In this tutorial you will learn how to host a public Docusaurus documentation project on Read the Docs Community. No prior experience with Docusaurus is required.
Note
Find out the differences between Read the Docs Community and Read the Docs for Business.
In the tutorial we will:
Import a Docusaurus project from a GitHub repository.
Tailor the project’s configuration.
Explore pull request previews, the build summary comment, visual diff, and link previews.
If you don’t have a GitHub account, you’ll need to register for a free account before you start.
Preparing your repository on GitHub
Sign in to GitHub and navigate to the Docusaurus tutorial GitHub template.
Click the green Use this template button, then click Create a new Repository. On the new page:
- Owner
Leave the default, or change it to something suitable for a tutorial project.
- Repository name
Something memorable and appropriate, for example
docusaurus-tutorial.- Visibility
Make sure the project is “Public”, rather than “Private”.
Click the green Create repository button to create a public repository that you will use in this Read the Docs tutorial, containing the following files:
.readthedocs.yamlRead the Docs configuration file. Required.
README.mdDescription of the repository.
docs/Directory holding the Docusaurus project, including
package.json,docusaurus.config.js,sidebars.js, and the Markdown source files underdocs/pages/.
Creating a Read the Docs account
To create a Read the Docs account, navigate to the Sign Up page and choose the option Sign up with GitHub and then Sign up using GitHub App.
Installing the Read the Docs GitHub App
For Read the Docs to access your docusaurus-tutorial repository,
install the Read the Docs Community GitHub App:
Open the GitHub App page and click Install.
Choose the GitHub account or organization that owns your
docusaurus-tutorialrepository.Select Only select repositories and pick
docusaurus-tutorial. You can grant access to additional repositories at any time from your GitHub settings.Click Install to complete the setup.
See also
- GitHub App
Details on what the GitHub App can do and the permissions it requests.
Adding the project to Read the Docs
To add your GitHub project to Read the Docs:
Click the Add project button on your dashboard.
Search for your
docusaurus-tutorialrepository, select it, and click Continue.Enter some details about your Read the Docs project:
- Name
The name of the project, used to create a unique subdomain for each project. so it is better if you prepend your username, for example
{username}-docusaurus-tutorial.- Repository URL
The URL that contains the documentation source. Leave the automatically filled value.
- Default branch
Name of the default branch of the project, leave it as
main.
Then click the Next button to create the project and open the project home.
Click This file exists to trigger the first build of your documentation.
You just created your first Docusaurus project on Read the Docs! 🎉
Checking the first build
Read the Docs will build your project documentation right after you create it.
To see the build logs:
Click the Your documentation is building link on the project home.
If the build has not finished by the time you open it, you will see a spinner next to a “Installing” or “Building” indicator, meaning that it is still in progress.
If the build has finished, you’ll see a green “Build completed” indicator, the completion date, the elapsed time, and a link to the generated documentation.
Click on View docs to see your documentation live!
Configuring the project
To update the project description and configure the notification settings:
Navigate back to the project page and click the ⚙ Admin button, to open the Settings page.
Update the project description with a short summary of what the documentation is about.
Set a project homepage and add a couple of public project tags such as
docusaurus, documentation.To get a notification if the build fails, click the Email Notifications link on the left, add your email address, and click the Add button.
Triggering builds from pull requests
Read the Docs can trigger builds from GitHub pull requests and show you a preview of the documentation with those changes.
To trigger builds from pull requests:
Click the Settings link on the left under the ⚙ Admin menu, check the “Build pull requests for this project” checkbox, and click the Save button at the bottom of the page.
Make some changes to your documentation:
Navigate to your GitHub repository, locating the file
docs/pages/intro.mdx, and clicking on the ✏️ icon on the top-right with the tooltip “Edit this file” to open a web editor.In the editor, add the following sentence to the file:
docs/pages/intro.mdxThis documentation is hosted on Read the Docs.
Write an appropriate commit message, choose the “Create a new branch for this commit and start a pull request” option.
Click the green Propose changes button to open the new pull request page, then click the Create pull request button below the description.
After opening the pull request, a Read the Docs check will appear indicating that it is building the documentation for that pull request. If you click the Details link while your project is building the build log will be opened. After building, this link opens the documentation directly.
Reviewing the pull request preview
Once the pull request build finishes, Read the Docs adds a comment to the pull request with a build overview that includes:
A link to the documentation preview.
The list of files that changed between the pull request and the latest version of the documentation.
This summary saves you from clicking through the build log to find the preview, and helps you confirm at a glance that the changes you expected are the ones being deployed.
Note
The build overview comment is only available for projects connected to a GitHub App. See Pull request previews for details on each of the pull request features.
Comparing changes with visual diff
Reading a Markdown diff is fine for prose, but it doesn’t always tell you what the page will look like once rendered. Visual diff highlights the changes directly on the rendered documentation pages, so you can review pull requests the same way readers will see them.
To enable visual diff:
Go to the Settings tab of your project.
Click Addons, then Visual diff.
Check Enable visual diff and click Save.
Open the pull request preview again. A new dropdown appears at the top right of the page listing every file that changed in the pull request. Pick a file to jump to it, then click Show diff (or press the d hotkey) to highlight the additions and deletions inline. Use the up/down arrows to step through each chunk.
Adding a configuration file
The Admin tab of the project home has some global configuration settings for your project.
Build process configuration settings live in the .readthedocs.yaml configuration file, in your Git repository, which means it can be different for every version or branch of your project.
Docusaurus is a Node.js application, so Read the Docs builds it by running a sequence of commands defined under build.jobs. The template repository ships with this file:
version: 2
build:
os: "ubuntu-22.04"
tools:
nodejs: "20"
jobs:
install:
- cd docs/ && npm install
build:
html:
- cd docs/ && npm run build
- mkdir --parents $READTHEDOCS_OUTPUT/html/
- cp --recursive docs/build/* $READTHEDOCS_OUTPUT/html/
The purpose of each key is:
versionRequired, specifies version 2 of the configuration file.
build.osRequired, specifies the Docker image used to build the documentation.
build.tools.nodejsSpecifies the Node.js version used during the build.
build.jobs.installCommands run during the install step. The Docusaurus project lives under
docs/, so wecdinto it and runnpm installto install Docusaurus and its dependencies.build.jobs.build.htmlCommands run to produce the HTML output. We
cd docs/and runnpm run buildto invoke Docusaurus, then copy the generateddocs/build/directory into$READTHEDOCS_OUTPUT/html/, where Read the Docs picks it up.
Tip
build.jobs is the recommended way to override the build process for tools that do not have first-class Read the Docs support.
Each step (install, build.html, post_build, etc.) can be overridden independently,
which keeps the rest of Read the Docs’ build pipeline intact.
Using a different Node.js version
To build your project with Node.js 22 instead of 20, edit the .readthedocs.yaml file and change the Node.js version like this:
version: 2
build:
os: "ubuntu-22.04"
tools:
nodejs: "22"
jobs:
install:
- cd docs/ && npm install
build:
html:
- cd docs/ && npm run build
- mkdir --parents $READTHEDOCS_OUTPUT/html/
- cp --recursive docs/build/* $READTHEDOCS_OUTPUT/html/
After you commit these changes, go back to your project home, navigate to the “Builds” page, and open the new build that just started. You will see in the build logs that the new toolchain version was used to install the dependencies and build the site.
Versioning documentation
Read the Docs supports having several versions of your documentation,
in the same way that you have several versions of your code.
By default, it creates a latest version
that points to the default branch of your version control system
(main in the case of this tutorial),
and that’s why the URLs of your HTML documentation contain the string /latest/.
Creating a new version of your documentation
Read the Docs automatically creates documentation versions from GitHub branches and tags that follow some rules about looking like version numbers, such as 1.0, 2.0.3 or 4.x.
To create version 1.0 of your code, and consequently of your documentation:
Navigate to your GitHub repository, click the branch selector, type
1.0.x, and click “Create branch: 1.0.x from ‘main’”.Check that you now have version
1.0.xin your project home, click on the Versions button, and under “Active Versions” you will see two entries:
The
latestversion, pointing to themainbranch.A new
stableversion, pointing to theorigin/1.0.xbranch.
When you created your branch, Read the Docs created a new special version called stable pointing to it. Once it builds, it appears in the flyout menu.
Setting stable as the default
To set stable as the default version, rather than latest, so that users see the stable documentation when they visit the root URL of your documentation:
In the ⚙ Admin menu of your project home, go to the Settings link, choose
stablein the “Default version” dropdown, and hit Save at the bottom.
Modifying versions
Both latest and stable are now active, which means that they are visible to readers and new builds can be triggered for them.
In addition to these, Read the Docs also created an inactive 1.0.x version, which always points to the 1.0.x branch of your repository.
To activate the 1.0.x version:
On your project home, go to “Versions”, locate
1.0.xunder “Activate a version”, and click the Activate button.On the “Activate” page with “Active” and “Hidden” checkboxes, check only “Active” and click Save.
Note
Read more about hidden versions in our documentation.
Enabling link previews for your readers
Link previews show readers the content of an internal link when they hover over it, so they can decide whether to follow the link without losing their place.
To enable link previews:
Go to your project’s dashboard and click the project name.
Go to Settings, then in the left bar, go to Addons.
Open Link previews and check Enabled.
Save your settings – a rebuild of your project isn’t required.
Open your published documentation and hover over any internal link. A small popup appears with the target page’s content. Link previews only render for internal links inside the main documentation content, so navigation bars and external links are unaffected.
Building only when documentation changes
If your repository hosts both your application code and its documentation, Read the Docs rebuilds your docs on every push by default — even when the change doesn’t touch any documentation files. Automation rules can gate builds on the contents of the webhook event from GitHub, so you only spend build time on commits and pull requests that actually affect the documentation.
To create a rule that builds your project only when documentation files change:
From the project home, open the ⚙ Admin menu and select Automation Rules, then click Add Rule.
Configure the rule:
- Description
Something memorable, for example
Build only on documentation changes.- Match
Any version.- Version types
Check Tag, Branch, and Pull request so the rule applies to every kind of build.
- Changed files
One pattern per line:
docs/* .readthedocs.yaml
- Action
Trigger build for version.
Click Save to create the rule.
From now on, Read the Docs only triggers a build when the push or pull request
modifies a file under docs/ or the .readthedocs.yaml configuration.
Pushes that only touch application code, tests, or unrelated files no longer
trigger a documentation build.
Important
Once a rule with the Trigger build for version action exists, builds are gated by automation rules: if no rule matches the incoming webhook event, no build runs. Make sure your patterns cover every path that should rebuild the docs before relying on this in production.
Note
Webhook-filter automation rules are only available for projects connected through the GitHub App.
See also
- Automation rules
Full reference for automation rules, including filters by commit message and pull request label.
Where to go from here
This is the end of the tutorial. You have accomplished a lot:
Created a Docusaurus project from a GitHub template.
Connected it to Read the Docs.
Built its HTML documentation.
Customized the build process with
build.jobs.Reviewed pull requests with the build summary comment and visual diff.
Enabled link previews for your readers.
Added new documentation versions.
Configured an automation rule to build only when documentation changes.
Nice work!
Here are some resources to help you continue learning about documentation and Read the Docs:
Learn more about the platform features.
Read the Docusaurus deployment guide for more advanced configuration tips.
See a list of Read the Docs Example projects.
Learn how to do specific tasks in the How-to guides A-Z.
Learn about private project support and other enterprise features in our commercial service guide.
Join a global community of fellow
documentariansin Write the Docs and its Slack workspace.Contribute to Read the Docs in Contributing to Read the Docs, we appreciate it!
Happy documenting!