Thanks for taking the time to contribute to MDN Web Docs! 🎉
This document covers project setup steps along with a set of guidelines for contributing to MDN Web Docs content. Everyone participating in this project is expected to follow our Code of Conduct. If you want to jump right in, see Getting started on MDN for an overview of how to join, and the Contribute page on MDN for a filtered list of tasks.
Before contributing, make sure you're familiar with the project guidelines and conventions:
- MDN guidelines - This page covers everything from how and what we write to general project guidelines.
- Writing style guide - This covers the language and style we use and how we write and format code examples.
- Guide to writing Markdown for MDN - Which Markdown features we support and custom extensions we've added.
We expect contributors to MDN to have some knowledge of web technologies before working on content. We've put together relevant resources to get up to speed on specific topics before contributing:
- Open source: If you're new to open source projects, see the open source etiquette page.
- Git and GitHub: If you are unfamiliar with these, GitHub for complete beginners is a good primer.
- Web technologies: HTML, CSS, JavaScript, and more are covered in our Learn web development tutorials.
- MDN repository: To find out where everything lives, see Where is everything on MDN?.
There are a few things to keep in mind about content on MDN and how it is maintained:
- A document's content is written in an
index.md
file. - A document's
index.md
starts with "front-matter" described in Front-matter. - Documents have corresponding folders (the JavaScript page's
index.md
is infiles/en-us/web/javascript
, for example). - Document folders may contain images referenced by the
index.md
file in that folder. - A document folder may contain child folders with child documents (e.g.,
files/en-us/web/javascript/closures/index.md
). - Redirects are specified in
_redirects.txt
. Do not edit this file manually! See Moving documents for details.
Each document's index.md
starts with front-matter, which is written in YAML.
The YAML is read by the MDN build system and is used to read the metadata of a document.
The front-matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines (---
).
Front-matter defines the document's title
, slug
, and optional tags
.
Here's an example of front-matter from the JavaScript page:
---
title: JavaScript
slug: Web/JavaScript
tags:
- JavaScript
- Landing
- Landing page
- Learn
- "l10n:priority"
---
You'll need a GitHub account to contribute to MDN Web Docs. If you are comfortable working with git and GitHub, you can skip ahead to Contributing to MDN. If you've created a new GitHub account and want to know what to do next, you can choose one of the following ways to manage changes:
- GitHub UI - This is the easiest way to contribute small changes described in Simple changes.
- GitHub Desktop - A desktop app for managing interaction with GitHub.
- GitHub CLI - A command-line wrapper for interacting with GitHub.
git
- You can usegit
from the command line to interact with GitHub. The examples in this document assume you are using this method. Thegit
cheatsheet and Using Git guide are useful resources for beginners and advanced users.
If you want to make a small change like fixing a typo, the GitHub UI is the easiest way to get started. If you've found a typo on the JavaScript landing page, for example, you can propose a fix as follows:
- Sign in to GitHub
- Navigate to https://github.com/mdn/content
- Find the source file
files/en-us/web/javascript/index.md
- Click the edit (pencil) button
From there, the GitHub UI will walk you through the rest by creating a fork and a branch to commit your changes to. After you have made changes to your branch, the goal is to open a pull request for your changes to be incorporated.
A pull request represents the work you want to be reviewed, approved, and merged into the main
branch of the MDN repository.
See the Creating a pull request for more details on creating and handling pull requests successfully.
If you're not certain of the changes that you want to make, get in touch with us! You can chat with us or file an issue.
Tip: You can click the Source on GitHub link at the bottom of an MDN page to jump directly to the page source on GitHub.
If you want make changes to more than one file, the GitHub UI is not very efficient because you have to make separate pull requests for each file you want to change.
Instead of using the GitHub UI, you need to use git
or a client like the GitHub Desktop or GitHub CLI.
The following examples are using plain git
commands, but you can use any of the clients mentioned above to perform the equivalent actions.
To fork and clone the repository:
-
Create a fork of the
mdn/content
repository to freely experiment with branches and changes. Assuming your GitHub username isoctocat
, your fork would be a copy of of themdn/content
repository in your account athttps://github.com/octocat/content
. -
Clone your fork to your local machine. Assuming your GitHub username is
octocat
, you would do something like this:# starting in a directory of your choice cd ~/repos # clone your fork of the repository git clone git@github.com:octocat/content.git
-
Create a
remote
to keep your clone and fork (https://github.com/octocat/content
) up-to-date. This example adds a remote namedupstream
, but you can name itmdn
or any other name you like.# starting in your clone directory cd ~/repos/content git remote add upstream git@github.com:mdn/content.git
When you run
git remote -v
, you'll see that you have two remotes:upstream
andorigin
. Theorigin
remote is your fork (https://github.com/octocat/content
) and theupstream
remote is themdn/content
repository. -
Keep your fork up-to-date often. You can do this by fetching the latest changes from the
mdn/content
repository and merging them into your fork.cd ~/repos/content # checkout your local clone's main branch git checkout main git fetch upstream # merge the latest content from the main branch of the mdn repository git merge upstream/main
-
Create a branch for your changes. This example creates a branch named
fix-typo
:cd ~/repos/content # checkout your local clone's main branch git checkout main # create a new branch named fix-typo git checkout -b fix-typo
The previous sections describe how to get started using the GitHub UI to make small changes to a single file and how to create a fork and clone the repository to prepare for making larger changes. This section describes how to build the project locally and how to prepare your changes for submission.
To set up the site locally, you need to have Node.js and Yarn installed. You can check if these are installed by running the following commands:
node -v
yarn -v
After you have installed Node.js and Yarn, you can install the dependencies using yarn
and start the local preview:
# Assuming your fork is in ~/repos/content
cd ~/repos/content
yarn
yarn start
Once started, a live preview is available at http://localhost:5042/
Set your preferred editor by adding EDITOR=...
into a .env
file in the project root.
To specify VS Code as your preferred editor, for example, use the following command:
echo 'EDITOR=code' >> .env
You can set the EDITOR
environment variable to any editor you like.
When browsing a page server locally, you can press Open in your editor to edit the current file in your preferred editor.
To edit files and track your changes, you should use feature branches.
Feature branches are created from the main
branch and should be named after the feature you're working on.
This will make it easier to submit a pull request for your changes.
Note: Open a discussion if your changes will contain large, complex or structural changes. Ask for feedback before embarking on large tasks.
-
When the server is running, make the changes you would like to make to one or more
index.md
files. -
Open a browser and navigate to the equivalent pages you've changed. If you changed
files/en-us/web/javascript/index.md
, you would navigate tohttp://localhost:5042/en-us/docs/web/javascript
in your browser, for example. -
Check for errors by clicking
Show flaws
on each previewed page. You may be able to fix flaws by running:yarn content flaws <page_slug>
-
Commit your changes to the branch (our example is using the
fix-typo
branch) and push the changes to your fork's remote:# Adding all files to the commit git add . # Making a commit with a message describing the changes git commit -m "Fix typo" # Pushing the commit to your fork git push # or "git push --set-upstream origin fix-typo" if you haven't pushed this branch before
Adding a new document is relatively straightforward, especially if you can start by copying the index.md
of a similar document.
There are a few things to keep in mind:
- Documents must be written in Markdown.
- A document is represented by an
index.md
file. - If you're creating a new CSS document for a property called
foo
, create a new folderfiles/en-us/web/css/foo/
and put the Markdown file in this folder (files/en-us/web/css/foo/index.md
). - A document's
index.md
file must start with front-matter that defines thetitle
,slug
, and optionaltags
. You might find it helpful to refer to the front-matter within a similar document'sindex.md
.
Moving one or more documents, or an entire tree of documents is made easier due to a special command that takes care of the details:
yarn content move <from-slug> <to-slug> [locale]
Important:
yarn content move
automatically adds redirect rules for moved content. Don't edit the_redirects.txt
file manually! If you need to add a redirect without moving a file, talk to us about it.
To use yarn content move
, provide the slug of the document you'd like to move (e.g., Learn/Accessibility
), and the slug of its new location (e.g., Learn/A11y
).
The locale of the existing document can be provided as an optional third argument (this defaults to en-US
).
If the document you'd like to move contains child documents (i.e. it represents a document tree), the yarn content move
command will move the entire tree.
Let's say you want to move the entire /en-US/Learn/Accessibility
tree to /en-US/Learn/A11y
, you can do so as follows:
-
Starting from a fresh branch:
cd ~/repos/content # Fetch the latest changes from the main branch on mdn/content git fetch upstream git checkout main git merge upstream/main # create a new branch for your work git checkout -b moving-a11y
-
Move files with
yarn content move
. This will delete and modify existing files, as well as create new files.yarn content move Learn/Accessibility Learn/A11y
-
Commit all of the changes and push your branch to the remote:
git add . git commit -m "Move Learn/Accessibility to Learn/A11y" git push # or git push --set-upstream origin moving-a11y
Deleting documents or a tree of documents is easy with the help of the yarn content delete
command:
yarn content delete <document-slug> [locale]
Important: you need to use the
yarn content delete
command to delete MDN documents. Don't delete directories from the repo, asyarn content delete
also handles other necessary changes such as updating the_wikihistory.json
file.
To use yarn content delete
, provide the slug of the document you'd like to delete (e.g., Learn/Accessibility
), and the locale as an optional second argument (this defaults to en-US
).
If the document has child documents (i.e. it represents a document tree), you must specify the -r, --recursive
option, or
the command will fail.
Say you want to delete the entire /en-US/Learn/Accessibility
tree:
-
Starting from a fresh branch:
cd ~/repos/content # Fetch the latest changes from the main branch on mdn/content git fetch upstream git checkout main git merge upstream/main # create a new branch for your work git checkout -b deleting-a11y
-
Perform the delete:
yarn content delete Learn/Accessibility --recursive
If the slug of the page you wish to delete contains special characters, include it in quotes:
yarn content delete "Mozilla/Add-ons/WebExtensions/Debugging_(before_Firefox_50)"
-
Add a redirect (if needed).
-
Commit all of the changes and push your branch to the remote:
git add . git commit -m "Delete Learn/Accessibility pages" git push # or git push --set-upstream origin moving-a11y
If you are moving a document as shown above you don't need to create a redirect. However, you may need to when deleting a document or otherwise fixing up a broken link.
The best way to do this is to use the yarn content add-redirect
command:
-
Start a fresh branch to work in:
cd ~/repos/content # Fetch the latest changes from the main branch on mdn/content git fetch upstream git checkout main git merge upstream/main # create a new branch for your work git checkout -b deleting-a11y
-
Add a redirect. The target page can a page on MDN or an external URL.
yarn content add-redirect /en-US/path/of/deleted/page /en-US/path/of/target/page
-
Commit all of the changed files and pushing your branch to your fork:
git add . git commit -m "Adding redirect after deleting Learn/Accessibility pages" git push # or git push --set-upstream origin deleting-a11y
Once you've made your changes and pushed them to a branch on your fork, you can create a pull request to propose your changes to the mdn/content
repository.
Someone from the MDN team or the MDN Web Docs community will review your changes and provide feedback.
For details on what to do next, see the pull request etiquette section to see how to handle pull requests and get your content merged successfully.
This is the exciting part of contributing to MDN as you're almost done with the contribution process! Here are some things to keep in mind at this point:
- Your pull request must be reviewed and approved before it's merged into the
main
branch. - You do not need to request a review; one or more reviewers will be selected for you automatically.
- It can be up to 48 hours for merged pull requests to have their changes published to MDN Web Docs.
During reviews, you may be asked to answer questions about your work or to make changes to your suggested edits. This is a common part of the process of making changes in open source projects. There are some important rules of etiquette to remember that will help during the review stage.
-
Check tests that are run automatically run for pull requests (see .github/workflows). If one or more of these tests fail, you must fix them. Your pull request will not be approved and merged if there are failing tests. If you don't know how to resolve the underlying issue(s), you can ask for help.
-
Resolve conflicts if your pull request has merge conflicts with the
main
branch. This is usually done by merging themain
branch into your feature branch (git pull upstream main
), and then pushing the updated branch to your fork (git push
). -
Group logical changes in each pull request so that it contains a single change or a related set of changes. If a pull request becomes too large or contains too many unrelated changes, a reviewer may close your pull request and ask you to submit a new pull request for each set of changes.
-
Don't re-open pull requests closed by a reviewer.
-
Don't use
git rebase
ofmain
over your branch. Your changes are replayed on top of the current main branch at that point in time. This might confuse reviewers as notifications on GitHub lead to nowhere.
When contributing to the content you agree to license your contributions according to our license.