Custom Tag Discovery
Custom tags are reusable .marko components discovered automatically from the filesystem or installed packages without explicit imports.
Priority
Marko resolves a tag name in the following order:
- Local variables (
PascalCaseidentifiers in scope) - Core tags (built-in tags cannot be shadowed by custom tags)
- Relative custom tags in
tags/directories up to the nearestpackage.json - Installed custom tags from dependencies in
package.json - Native HTML, SVG, and MathML tags
Local Variables
When a tag name starts with an uppercase letter, Marko checks local scope first. This handles explicitly imported templates and <define> snippets:
import MyTag from "./my-tag.marko";
<MyTag/>import MyTag from "./my-tag.marko";
MyTag<define/MyTag|input|><span>Hello ${input.name}</span></define>
<MyTag name="HTML"/>
<MyTag name="Marko"/><define/MyTag|input: { name: string }|><span>Hello ${input.name}</span></define>
<MyTag name="HTML"/>
<MyTag name="Marko"/>define/MyTag|input|
span -- Hello ${input.name}
MyTag name="HTML"
MyTag name="Marko"define/MyTag|input: { name: string }|
span -- Hello ${input.name}
MyTag name="HTML"
MyTag name="Marko"Reference a non-PascalCase local variable using dynamic tag syntax:
import { camelCaseTag } from "somewhere";
<${camelCaseTag}/>import { camelCaseTag } from "somewhere";
${camelCaseTag}Native Tag Registration
The compiler recognizes standard HTML, SVG, and MathML tags. To emit non-standard elements or custom elements verbatim as native HTML tags, register them in a marko.json beside the template or in an ancestor directory:
{
"<x-datepicker>": { "html": true }
}Supporting Files
Marko automatically discovers adjacent stylesheets for any .marko template using a single extension (<name>.style.<ext>, or style.<ext> next to index.marko). A tag directory may also include a marko-tag.json:
tags/
card.marko
card.style.css
modal/
index.marko
style.scss
widget/
index.marko
marko-tag.jsonAny single preprocessor extension (.css, .scss, .less, etc.) is supported.
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.