# A basic mermaid User-Guide for Beginners **Edit this Page** [![N|Solid](./img/GitHub-Mark-32px.png)](https://github.com/mermaid-js/mermaid/blob/develop/docs/n00b-gettingStarted.md) Creating diagrams and charts using mermaid code is simple. The code is turned into a diagram in the web page with the use of a mermaid renderer. The mermaid renderer is a piece of javascript that parses mermaid definitions, when called. This then renders a diagram based on that code in SVG, alternatively it Most web browsers, such as Firefox, Chrome and Safari, can render mermaid, Internet Explorer however cannot. ## For beginners, there are four relatively easy ways you can use mermaid: 1. Using the mermaid [live editor](https://mermaid-js.github.io/mermaid-live-editor/). For some popular video tutorials on the live editor go to [Overview](./n00b-overview.md). 2. Using one of the many [mermaid plugins](https://mermaid-js.github.io/mermaid/#/integrations). 3. Calling mermaid renderer with an absolute link through HTML. 4. Installing mermaid with npm and hosting it on a webpage using a relative link in the ` ``` ### b. The embedded mermaid diagram definition needs to be contains inside a `
` tag that signifies that it is a mermaid diagram: ``` Here is a mermaid diagram:
graph TD A[Client] --> B[Load Balancer] B --> C[Server01] B --> D[Server02]
``` **Notes**: every mermaid chart/graph/diagram definition, has to have separate `
` tags. ### c. The `mermaid.initialize()` API call `mermaid.initialize()` calls take all the definitions contained in `
` tags it can find in the html body and starts to render them one by one. It is called this way: ``` ``` **Notes**:It is good practice to keep the `mermaid.initialize()` API call right next the `mermaid.min.js` `script` tag. startOnLoad is a parameter that can optionally be changed to false, this would then prevent mermaid from immediately rendering upon loading. ### If the three steps mentioned are followed you will end up with something like this: ``` Here is one mermaid diagram:
graph TD A[Client] --> B[Load Balancer] B --> C[Server1] B --> D[Server2]
And here is another:
graph TD A[Client] -->|tcp_123| B(Load Balancer) B -->|tcp_456| C[Server1] B -->|tcp_456| D[Server2]
``` **Notes**: This has to be saved in an `HTML` file and opened with a browser. --- ## 4. Calling mermaid from a relative link. This method is similar to 3, if only a little more involved. The difference may be very subtle even, but it offers its own advantages, mainly in speed. 1. install node v10 or 12, which would have npm 2. download yarn using npm by entering the command below: npm install -g yarn 3. After yarn installs, enter the following command: yarn add mermaid 4. After downloading mermaid, you can then open the mermaid file you’ve downloaded and go to the `dist` folder. 5. Find the `mermaid.min.js` file, a. select the file. b. press the shift key and right click on it c. select copy as path from the options. 6. Paste it within the `script` tag as the `src`. ``` ``` 7. It should look something like this ``` ``` 8. Add the graph and diagram definitions as you would in number 3. a. be mindful of the `div` tags. 9. Save, load/edit your HTML file to your liking. **Note** placing the HTML file on the same folder the `mermaid` file you've downloaded is a good practice and allows you to shorten the address on the `src` section. **As seen here, in this full example:** ```
graph LR A --- B B-->C[fa:fa-ban forbidden] B-->D(fa:fa-spinner);
graph TD A[Client] --> B[Load Balancer] B --> C[Server1] B --> D[Server2]
``` **Three additional comments from Knut Sveidqvist, creator of mermaid:** - In early versions of mermaid, the `