Timeline Diagram

Timeline: This is an experimental diagram for now. The syntax and properties can change in future releases. The syntax is stable except for the icon integration which is the experimental part.

β€œA timeline is a type of diagram used to illustrate a chronology of events, dates, or periods of time. It is usually presented graphically to indicate the passing of time, and it is usually organized chronologically. A basic timeline presents a list of events in chronological order, usually using dates as markers. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person’s life.” Wikipedia

An example of a timeline.

2002LinkedIn2004FacebookGoogle2005Youtube2006TwitterHistory of Social Media Platform

Syntax

The syntax for creating Timeline diagram is simple. You always start with the timeline keyword to let mermaid know that you want to create a timeline diagram.

After that there is a possibility to add a title to the timeline. This is done by adding a line with the keyword title followed by the title text.

Then you add the timeline data, where you always start with a time period, followed by a colon and then the text for the event. Optionally you can add a second colon and then the text for the event. So, you can have one or more events per time period.

{time period} : {event}

or

{time period} : {event} : {event}

or

{time period} : {event}
              : {event}
              : {event}

NOTE: Both time period and event are simple text, and not limited to numbers.

Let us look at the syntax for the example above.

2002LinkedIn2004FacebookGoogle2005Youtube2006TwitterHistory of Social Media Platform

In this way we can use a text outline to generate a timeline diagram. The sequence of time period and events is important, as it will be used to draw the timeline. The first time period will be placed at the left side of the timeline, and the last time period will be placed at the right side of the timeline.

Similarly, the first event will be placed at the top for that specific time period, and the last event will be placed at the bottom.

Grouping of time periods in sections/ages

You can group time periods in sections/ages. This is done by adding a line with the keyword section followed by the section name.

All subsequent time periods will be placed in this section until a new section is defined.

If no section is defined, all time periods will be placed in the default section.

Let us look at an example, where we have grouped the time periods in sections.

17th-20th centuryIndustry 1.0Machinery, Waterpower, SteampowerIndustry 2.0Electricity, Internalcombustion engine,Mass productionIndustry 3.0Electronics,Computers,Automation21st centuryIndustry 4.0Internet, Robotics,Internet of ThingsIndustry 5.0Artificial intelligence,Big data,3D printingTimeline of Industrial Revolution

As you can see, the time periods are placed in the sections, and the sections are placed in the order they are defined.

All time periods and events under a given section follow a similar color scheme. This is done to make it easier to see the relationship between time periods and events.

Wrapping of text for long time-periods or events

By default, the text for time-periods and events will be wrapped if it is too long. This is done to avoid that the text is drawn outside the diagram.

You can also use <br> to force a line break.

Let us look at another example, where we have a long time period, and a long event.

Stone Age7600 BCBritain's oldestknown house wasbuilt in Orkney,Scotland6000 BCSea levels rise andBritain becomes anisland.The people who livehere arehunter-gatherers.Bronze Age2300 BCPeople arrive fromEurope and settle inBritain.They bring farmingand metalworking.New styles of potteryand ways of buryingthe dead appear.2200 BCThe last majorbuilding works arecompleted atStonehenge.People now burytheir dead in stonecircles.The first metalobjects are made inBritain.Some othernice things happen.it is a good time tobe alive.England's History Timeline

2023 Q1Release Personal TierButtet 1sub-point 1asub-point 1bsub-point 1cBullet 2sub-point 2asub-point 2b2023 Q2Release XYZ TierButtet 3sub-point3asub-point 3bsub-point 3cBullet 4sub-point 4asub-point 4bMermaidChart 2023 Timeline

Styling of time periods and events

As explained earlier, each section has a color scheme, and each time period and event under a section follow the similar color scheme.

However, if there is no section defined, then we have two possibilities:

  1. Style time periods individually, i.e. each time period(and its coressponding events) will have its own color scheme. This is the DEFAULT behavior.

2002LinkedIn2004FacebookGoogle2005Youtube2006TwitterHistory of Social Media Platform

Note that there are no sections defined, and each time period and its corresponding events will have its own color scheme.

  1. Disable the multiColor option using the disableMultiColor option. This will make all time periods and events follow the same color scheme.

You will need to add this option either via mermaid.intialize function or directives.

mermaid.initialize({
        theme: 'base',
        startOnLoad: true,
        logLevel: 0,
        timeline: {
          disableMulticolor: false,
        },
        ...
        ...

let us look at same example, where we have disabled the multiColor option.

2002LinkedIn2004FacebookGoogle2005Youtube2006TwitterHistory of Social Media Platform

Customizing Color scheme

You can customize the color scheme using the cScale0 to cScale11 theme variables, which will change the background colors. Mermaid allows you to set unique colors for up-to 12 sections, where cScale0 variable will drive the value of the first section or time-period, cScale1 will drive the value of the second section and so on. In case you have more than 12 sections, the color scheme will start to repeat.

If you also want to change the foreground color of a section, you can do so use theme variables corresponding cScaleLabel0 to cScaleLabel11 variables.

NOTE: Default values for these theme variables are picked from the selected theme. If you want to override the default values, you can use the initialize call to add your custom theme variable values.

Example:

Now let’s override the default values for the cScale0 to cScale2 variables:

2002LinkedIn2004FacebookGoogle2005Youtube2006Twitter2007Tumblr2008Instagram2010PinterestHistory of Social Media Platform

See how the colors are changed to the values specified in the theme variables.

Themes

Mermaid supports a bunch of pre-defined themes which you can use to find the right one for you. PS: you can actually override an existing theme’s variable to get your own custom theme going. Learn more about theming your diagram here.

The following are the different pre-defined theme options:

  • base
  • forest
  • dark
  • default
  • neutral

NOTE: To change theme you can either use the initialize call or directives. Learn more about directives Let’s put them to use, and see how our sample diagram looks in different themes:

Base Theme

2002LinkedIn2004FacebookGoogle2005Youtube2006Twitter2007Tumblr2008Instagram2010PinterestHistory of Social Media Platform

Forest Theme

2002LinkedIn2004FacebookGoogle2005Youtube2006Twitter2007Tumblr2008Instagram2010PinterestHistory of Social Media Platform

Dark Theme

2002LinkedIn2004FacebookGoogle2005Youtube2006Twitter2007Tumblr2008Instagram2010PinterestHistory of Social Media Platform

Default Theme

2002LinkedIn2004FacebookGoogle2005Youtube2006Twitter2007Tumblr2008Instagram2010PinterestHistory of Social Media Platform

Neutral Theme

2002LinkedIn2004FacebookGoogle2005Youtube2006Twitter2007Tumblr2008Instagram2010PinterestHistory of Social Media Platform

Integrating with your library/website.

Timeline uses experimental lazy loading & async rendering features which could change in the future.The lazy loading is important in order to be able to add additional diagrams going forward.

You can use this method to add mermaid including the timeline diagram to a web page:

<script type="module">
  import mermaid from '<CDN_URL>/mermaid@<MERMAID_VERSION>/dist/mermaid.esm.min.mjs';
</script>

You can also refer the implementation in the live editor here to see how the async loading is done.