Marp

Directives

This is a stub page!

Marp has an extended syntax called "Directives" to control theme, page number, header, footer, and other slide elements.

The syntax of directives is inherited from Marpit framework. Please note that different directives are used by each Marp tool.

Usage

Marp parses directives as YAML.

HTML comment

  1. <!--
  2. theme: default
  3. paginate: true
  4. -->

Front matter

Like many tools (e.g. Jekyll site generator), Marp uses YAML front matter. Directives can be defined in front matter.

YAML front matter must be at the beginning of a Markdown document and enclosed by dashed rulers.

  1. ---
  2. theme: default
  3. paginate: true
  4. ---

Note that the dashed ruler is also used to indicate where Marp should split slides. Marp uses the first two dashed rulers to indicate YAML front matter. Subsequent dashed rulers indicate slide breaks.

TIP: Defining directives in the front matter is equivalent to setting the directives using an HTML comment on the first page. Suppose your favorite Markdown editor does not support the front matter syntax. In that case, you can safely define the directive in an HTML comment instead.

Type of directives

There are two types of Marp directives:

  • Global directives - Controlling settings for the all slides (e.g. theme, size)
  • Local directives - Controlling setting values for one slide (e.g. paginate, header, footer)

You can define both directives in the same way. You can mix definitions too. The only difference is that some settings apply to all slides, and some apply to only one slide.

Global directives

Global directives are settings for the entire slide deck.

NameDescription
themeSet a theme name for the slide deck ▶️
styleSpecify CSS for tweaking theme
headingDividerSpecify heading divider option ▶️
sizeChoose the slide size preset provided by theme
mathChoose a library to render math typesetting ▶️
titleSet a title of the slide deck
authorSet an author of the slide deck
descriptionSet a description of the slide deck
keywordsSet comma-separated keywords for the slide deck
urlSet canonical URL for the slide deck (for HTML export)
imageSet Open Graph image URL (for HTML export)
marpSet whether or not enable Marp feature in VS Code

If you set the same global directive multiple times, Marp will use the last defined value.

Local directives

Local directives are settings for a specific slide.

NameDescription
paginateShow page number on the slide if set to true ▶️
headerSpecify the content of the slide header ▶️
footerSpecify the content of the slide footer ▶️
classSet HTML class attribute for the slide element <section>
backgroundColorSet background-color style of the slide
backgroundImageSet background-image style of the slide
backgroundPositionSet background-position style of the slide
backgroundRepeatSet background-repeat style of the slide
backgroundSizeSet background-size style of the slide
colorSet color style of the slide

Inheritance

Slides will inherit setting values of local directives from the immediately previous slide unless a local directive is explicitly set for the current slide. In other words, defined local directives will apply to both the defined page and subsequent pages.

For example, the Markdown for this set of slides defines the backgroundColor directive on the second page. Because subsequent pages inherit local directives, the third page will also have the same color.

  1. # Page 1

  2. Go to next page :arrow_right:

  3. ---

  4. <!-- backgroundColor: lightblue -->

  5. # Page 2

  6. ## This page has a light blue background.

  7. ---

  8. # Page 3

  9. ## This page also has the same light blue background.

Scoped local directives

If you want a local directive to apply only to the current page, add the underscore prefix _ to the name of directives.

The value of a scoped directive will be given priority over an inherited value, and subsequent pages will not inherit the value of the scoped directive.

  1. <!-- color: red -->

  2. # Page 1

  3. This page has red text.

  4. ---

  5. <!-- _color: blue -->

  6. # Page 2

  7. This page has blue text, specified by a scoped local directive.

  8. ---

  9. # Page 3

  10. Go back to red text.

The underscore prefix can be added to any local directives.

Diagram

The diagram of local directives and scoped directives
The diagram of local directives and scoped directives

Theme

Page number

To add page number to the slide, set the paginate local directive to true.

  1. <!-- paginate: true -->

  2. You can see the slide number in the lower right.

Refer to theme guide for details on how to style a slide number.

Skip pagination in the title slide

Just move the definition of the paginate directive to the second slide.

  1. # Title slide

  2. ---

  3. <!-- paginate: true --->

  4. ## Start pagination from this slide.

You can also use scoped directive to disable pagination in the title slide.

  1. ---
  2. paginate: true
  3. _paginate: false
  4. ---

  5. # Title slide

  6. ---

  7. ## Start pagination from this slide.

Use header and footer local directives to add headers and footers to slides.

  1. <!--
  2. header: Header content
  3. footer: Footer content
  4. -->

  5. # Header and footer

Refer to theme guide for details on how to style header and footer.

Markdown formatting

You can use inline Markdown formatting (italic, bold, inline image, etc) in header and footer like this:

  1. ---
  2. header: '**bold** _italic_'
  3. footer: '![image](https://example.com/image.jpg)'
  4. ---

To make directives parsable as valid YAML, you can wrap content with (double-)quotes.

Set the value of a directive to an empty string value to reset the header and footer in the middle of the slide deck.

  1. ---
  2. header: '**Header**'
  3. footer: '_Footer_'
  4. ---

  5. # Example

  6. ---

  7. <!--
  8. header: ''
  9. footer: ''
  10. -->

  11. ## Reset header and footer

Styling slide

Shorthand

Editor integration