If you followed the guide to exporting a notebook as a web page, you ended up with one self-contained HTML file and a link that works. The weak point is where that file lives. A paste-and-go host gives you a URL in seconds, but the page exists in a tab somewhere outside your work, and when the notebook changes you have to remember to re-upload it.
GitHub Pages fixes both. If the notebook already lives in a repository — and most do — you can serve the exported HTML from that same repository, at a URL that never changes, rebuilt by a push. It is free for public repos, it needs no build step for a static file, and the whole setup is a file, a setting and about two minutes.
This is the repository half of the problem. For the export itself, and for the checks worth doing before a page goes public, start with the HTML sharing guide.
Why GitHub Pages suits notebooks
Three properties line up unusually well:
- The source and the render live together. The
.ipynbis the truth; the HTML is a build artifact. Keeping them in one repo means the page and the code can never drift apart by accident. - The URL is stable and yours. A project site is
https://yourname.github.io/repo-name/. It does not expire, it does not need a credit card, and it survives you forgetting about it. - A push can be the build. With an Actions workflow,
git pushre-exports the notebook and republishes the page. Nobody has to remember the upload step.
The catch is that Pages is a static file host with a public-by-default model. Both of those shape the setup below.
Step 1: export to standalone HTML first
Do not upload the .ipynb and hope Pages renders it. GitHub shows notebook files in its own viewer, but that viewer is a repository page, not a website: it has GitHub’s chrome around it, it is not something you would send to a client, and it disappears if the repo goes private.
Export instead:
jupyter nbconvert --to html --embed-images notebook.ipynb
--embed-images is the flag that makes the output a single file. Without it you get notebook.html plus a notebook_files/ folder of PNGs, and the page breaks the moment one of them is left behind. The browser converter produces the same single-file result if you would rather not install anything.
Then open the HTML offline, from an empty folder, and confirm the plots and the styling survive. That check is covered in detail in the sharing guide; it is worth doing before the file becomes a public URL rather than after.
Step 2: decide where the file goes in the repository
Pages publishes from one of three places, and the choice determines your URL:
| What you publish | Where the file goes | Resulting URL |
|---|---|---|
| Branch root | index.html at the repo root |
yourname.github.io/repo-name/ |
docs/ folder on a branch |
docs/index.html |
yourname.github.io/repo-name/ |
| GitHub Actions artifact | whatever the workflow uploads | yourname.github.io/repo-name/ |
For a single notebook, the branch root with an index.html is the least moving parts. Name the export index.html rather than notebook.html so the bare directory URL serves it:
jupyter nbconvert --to html --embed-images \
--output index --output-dir . notebook.ipynb
If the repository already has a README and code at its root, use docs/ instead — it keeps the published page in its own folder and out of the way of the source tree.
Two repository details matter:
- Add an empty
.nojekyllfile. Pages runs a branch through Jekyll by default, and Jekyll silently drops files and folders whose names start with an underscore. Notebook exports usually avoid those names, but a_filesfolder or a theme asset can trip it, and the failure mode is a 404 with no error message. An empty.nojekyllat the publish root turns the processing off. - Commit the HTML, or generate it in CI. Committing a 2–5 MB HTML file is fine and simple; it does mean the diff is unreadable. The Actions route in Step 4 keeps the artifact out of history.
Step 3: turn on Pages
In the repository: Settings → Pages. Under Build and deployment, set Source to Deploy from a branch, pick the branch (main) and the folder (/ (root) or /docs), then Save.
The first deploy takes a minute or two. The Pages settings page shows the URL and the status of the last build; when it says the site is live, open the URL in a private window, because your own browser may still hold a cached 404 from before the build finished.
Project sites live under a path, yourname.github.io/repo-name/, which matters for any relative link inside the exported HTML. The notebook export uses inline styles and inline images, so there is usually nothing to break — but if you added a link to a sibling file, make it relative (./data.csv), not absolute (/data.csv), or it will resolve against the domain root and miss the repo path.
Step 4 (optional): rebuild on every push
Committing the HTML works until the notebook changes and the committed copy does not. The durable version runs nbconvert in CI and publishes the artifact, so the page is always the notebook at HEAD.
Set Source to GitHub Actions first, then add .github/workflows/publish-notebook.yml:
name: Publish notebook
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install nbconvert
- run: |
mkdir -p public
jupyter nbconvert --to html --embed-images \
--output index --output-dir public notebook.ipynb
touch public/.nojekyll
- uses: actions/upload-pages-artifact@v3
with:
path: public
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
The permissions block is not boilerplate — without pages: write and id-token: write the deploy step fails with an opaque token error. The concurrency group prevents two pushes in quick succession from racing to publish.
One warning: this workflow exports the stored outputs, exactly like a local run. It does not execute the notebook, which is the right default — running untrusted cells in CI is how credentials leak. If you do want fresh outputs, run the notebook locally and commit the result, or use --execute only on a notebook whose code you fully trust, with a token that can read nothing but the repository.
What GitHub Pages will not do
Knowing the limits saves a confusing afternoon later:
- Public repositories on a free plan. Pages on a private repo needs GitHub Pro, Team or Enterprise. If the notebook cannot be public, this host is the wrong host — a single-file service with an unguessable name, or a PDF sent directly, is the honest alternative.
- 1 GB per published site, 100 GB of bandwidth a month, roughly 10 builds an hour. A notebook page is a few megabytes, so the size limit only matters if you are publishing a whole course of them in one repo.
- No access control. A Pages URL is public and indexable. A long repo name is not a password. Redact the outputs in the notebook before the export, not after.
- A short cache. Pages serves through a CDN with a cache measured in minutes. Re-deploying does not always show the new page immediately in a browser that has already loaded it; a hard reload settles it.
- No server-side anything. No forms, no API routes, no Python. If the notebook needs a running kernel, Pages serves the reading copy, not the app.
Checking the published page
Before you send the link:
- Open it in a private window, on a phone-sized viewport.
- Confirm the tab title is the notebook’s first heading, not
index.html. - Scroll to the widest table and the largest figure; that is where a bad export shows up.
- Click every link in the page and confirm none of them point at
localhostor a relative file that only exists on your laptop. - If the page should be findable, check it is not blocked by a
<meta name="robots" content="noindex">left over from a draft export.
The short version
- Export with
nbconvert --to html --embed-images, or use the browser converter, and verify the file works alone and offline. - Commit it as
index.htmlat the repo root or indocs/, alongside an empty.nojekyll. - Settings → Pages → deploy from that branch and folder.
- Optionally add the Actions workflow so each push re-exports the notebook.
- Share
yourname.github.io/repo-name/and keep the.ipynbas the source of truth.
For anything that has to leave the browser as a fixed document — a submission, a signed report, a handout — the format question is a different one: the IPYNB to PDF guide covers that route, and DOCX versus PDF covers which of the two to send.