Setup

Pass a class to the component and place overrides in your stylesheet. No package stylesheet or Tailwind configuration is required. In a Svelte <style> block, use :global(...) so selectors reach the child renderer's markup.

<script lang="ts">
	import { MarkdownViewer } from 'markdown-svelte'

	const source = '# Hello, **Svelte**!'
</script>

<MarkdownViewer markdown={source} class="document" />

<!-- Or: <MarkdownStream {nodes} class="document" /> -->

<style>
	:global(.document) {
		--markdown-color-text: #292b29;
		--markdown-color-link: #a63f24;
		--markdown-color-surface: #f3f4ee;
		--markdown-radius: 0;
		--markdown-font-sans: system-ui, sans-serif;
		font-size: 1.05rem;
		line-height: 1.8;
	}

	:global(.document .markdown-svelte-heading--2) {
		border-bottom: 0;
		font-family: Georgia, serif;
	}
</style>

In a global CSS file, omit :global(...). The examples below use that form. Base element styles use :where(...) to keep specificity low, so ordinary class selectors can override them. Existing app styles for tags such as a or code can also take precedence; use a scoped element selector when needed.

Theme variables

Set these on the component's class or an ancestor. Font size, line height, spacing, and document background use normal CSS properties. The default palette is light; set colors explicitly for a dark surface.

Document theme defaults
VariableDefaultApplies to
--markdown-color-text#253044Document text.
--markdown-color-muted#667085Secondary text, blockquotes, and fallback labels.
--markdown-color-border#d7dde7Rules, table borders, and element outlines.
--markdown-color-surface#f5f7faBlockquotes, containers, and math blocks.
--markdown-color-surface-strong#e9edf3Table headers.
--markdown-color-link#0b62c4Links and footnote navigation.
--markdown-color-accent#087164Blockquote borders, checkboxes, and default admonitions.
--markdown-color-code#e8edf5Inline code and inline math backgrounds.
--markdown-code-background#111827Fenced code block background.
--markdown-code-text#e5edf8Fenced code block text.
--markdown-radius0.55remBlock, table, and image corners. Inline code and math have their own radius.
--markdown-font-sansui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serifDocument font family.
--markdown-font-mono'SFMono-Regular', Consolas, 'Liberation Mono', monospaceCode and math font family.

These variables cover shared theme values. Use element classes for details such as highlight colors, code-toolbar colors, or inline-code corners. Properties beginning with --_markdown- are internal resolved values.

Element reference

Every class below includes the full selector. Some elements only appear for the corresponding parser node type.

Document

The class prop is added to the root article. Scope overrides to that class when a page has several documents.

Document selectors
SelectorElement
.markdown-svelteRoot article for all renderers; also has [data-markdown-svelte].
.markdown-svelte-streamAdditional root class for MarkdownStream; also has [data-markdown-svelte-stream].
.document {
	max-width: 72ch;
	margin-inline: auto;
	line-height: 1.8;
}

Headings and paragraphs

Use the level modifier to change one heading level. Set overall text size and line height on the document.

Headings and paragraphs selectors
SelectorElement
.markdown-svelte-headingAll headings, h1 through h6.
.markdown-svelte-heading--1, .markdown-svelte-heading--2, .markdown-svelte-heading--3, .markdown-svelte-heading--4, .markdown-svelte-heading--5, .markdown-svelte-heading--6Individual heading levels.
.markdown-svelte-paragraphParagraph (p).
.markdown-svelte-inlineInline group (span).
.markdown-svelte-textText node wrapper (span).
.markdown-svelte-hardbreakExplicit line break (br).
.document .markdown-svelte-heading--2 {
	margin-top: 2.5em;
	border-bottom: 0;
}

.document .markdown-svelte-paragraph {
	margin-block: 1em;
}

Inline formatting and links

Highlights and other inline details can be styled directly when the theme variables do not cover them.

Inline formatting and links selectors
SelectorElement
.markdown-svelte-strongBold text (strong).
.markdown-svelte-emphasisEmphasis (em).
.markdown-svelte-strikethroughDeleted text (del).
.markdown-svelte-highlightHighlighted text (mark).
.markdown-svelte-insertInserted text (ins).
.markdown-svelte-subscriptSubscript (sub).
.markdown-svelte-superscriptSuperscript (sup).
.markdown-svelte-inline-codeInline code (code).
.markdown-svelte-linkMarkdown link (a).
.markdown-svelte-emojiEmoji wrapper (span).
.markdown-svelte-referenceUnresolved reference text (span).
.document .markdown-svelte-link {
	text-decoration-thickness: 0.1em;
	text-underline-offset: 0.2em;
}

.document .markdown-svelte-link:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

.document .markdown-svelte-highlight {
	background: #e5edcf;
	color: #34451f;
}

.document .markdown-svelte-inline-code {
	border: 0;
	border-radius: 0;
}

Lists and definitions

Task checkboxes are disabled display elements. Definition classes apply to definition-list nodes supplied by the parser.

Lists and definitions selectors
SelectorElement
.markdown-svelte-listOrdered and unordered lists.
.markdown-svelte-list--orderedOrdered list (ol).
.markdown-svelte-list--unorderedUnordered list (ul).
.markdown-svelte-list-itemList item (li).
.markdown-svelte-list-item--taskTask-list item modifier.
.markdown-svelte-task-contentTask item content wrapper (div).
.markdown-svelte-checkboxDisabled checkbox (input).
.markdown-svelte-definition-listDefinition list (dl).
.markdown-svelte-definition-termDefinition term (dt).
.markdown-svelte-definition-descriptionDefinition body (dd).
.document .markdown-svelte-list--unordered {
	list-style-type: square;
}

.document .markdown-svelte-list-item::marker {
	color: #6d7461;
}

.document .markdown-svelte-checkbox {
	accent-color: #6d7461;
}

.document .markdown-svelte-definition-description {
	margin-inline-start: 1.5rem;
}

Quotes, callouts, and rules

Admonitions expose their lowercase kind through data-kind, such as warning, caution, danger, or error. Generic containers have a separate title class.

Quotes, callouts, and rules selectors
SelectorElement
.markdown-svelte-blockquoteBlockquote.
.markdown-svelte-thematic-breakThematic break (hr).
.markdown-svelte-admonitionAdmonition wrapper (aside).
.markdown-svelte-admonition-titleAdmonition title (strong).
.markdown-svelte-containerGeneric fenced container (aside).
.markdown-svelte-container-titleContainer title (strong).
.document .markdown-svelte-blockquote {
	border-radius: 0;
	background: transparent;
	font-style: italic;
}

.document .markdown-svelte-admonition[data-kind='warning'] {
	border-color: #986315;
	background: #fff8e8;
}

.document .markdown-svelte-admonition[data-kind='warning'] .markdown-svelte-admonition-title {
	color: #70460c;
}

.document .markdown-svelte-thematic-break {
	margin-block: 2rem;
}

Code blocks and diffs

Code is rendered as text; no syntax highlighter is bundled. Diff blocks show split panes when the node includes originalCode or updatedCode. The copy button exposes data-state="idle", "copied", or "failed".

Code blocks and diffs selectors
SelectorElement
.markdown-svelte-code-blockOuter code block (div).
.markdown-svelte-code-headerLanguage and copy toolbar (div).
.markdown-svelte-code-languageLanguage label (span).
.markdown-svelte-code-copyCopy button (button).
.markdown-svelte-code-preCode surface (pre); contains code.
.markdown-svelte-diffSplit diff layout (div).
.markdown-svelte-diff-paneDiff pane (section).
.markdown-svelte-diff-pane--original, .markdown-svelte-diff-pane--updatedOriginal and updated pane modifiers.
.markdown-svelte-diff-labelPane label (strong).
.document .markdown-svelte-code-block {
	border-radius: 0;
	box-shadow: none;
}

.document .markdown-svelte-code-pre {
	font-size: 0.9rem;
}

.document .markdown-svelte-code-copy[data-state='copied'] {
	color: #bbf7d0;
}

Tables

Keep horizontal scrolling on the wrapper for narrow screens. Column alignment comes from Markdown alignment markers and is applied as an inline text-align style on each cell.

Tables selectors
SelectorElement
.markdown-svelte-table-wrapperScrollable table wrapper (div).
.markdown-svelte-tableTable.
.markdown-svelte-table-headHeader group (thead).
.markdown-svelte-table-bodyBody group (tbody).
.markdown-svelte-table-rowTable row (tr).
.markdown-svelte-table-cellAll header and body cells.
.markdown-svelte-table-cell--headerHeader cell (th).
.markdown-svelte-table-cell--bodyBody cell (td).
.document .markdown-svelte-table-wrapper {
	border: 0;
	border-radius: 0;
}

.document .markdown-svelte-table-cell {
	padding: 0.75rem 1rem;
}

.document .markdown-svelte-table-body .markdown-svelte-table-row:nth-child(even) {
	background: #f3f4ee;
}

Images

Images fit their container by default. The fallback span displays alt text when the source URL is missing or rejected by the URL policy.

Images selectors
SelectorElement
.markdown-svelte-imageImage (img).
.markdown-svelte-image-fallbackAlt-text fallback (span).
.document .markdown-svelte-image {
	border: 0;
	border-radius: 0;
	margin-inline: 0;
}

Math

Math is displayed as source text. Styling these elements does not typeset the expression; no math renderer is bundled.

Math selectors
SelectorElement
.markdown-svelte-math-inlineInline math source (code).
.markdown-svelte-math-blockBlock math source (pre); contains code.
.document .markdown-svelte-math-inline {
	border: 0;
	background: transparent;
}

.document .markdown-svelte-math-block {
	border-radius: 0;
	text-align: center;
}

Footnotes

Style classes rather than generated IDs. idPrefix namespaces IDs when multiple rendered documents share a page.

Footnotes selectors
SelectorElement
.markdown-svelte-footnoteFootnote definition wrapper (div).
.markdown-svelte-footnote-labelDefinition number (sup).
.markdown-svelte-footnote-contentDefinition content (div).
.markdown-svelte-footnote-referenceInline reference (sup).
.markdown-svelte-footnote-reference-linkLink from a reference to its definition (a).
.markdown-svelte-footnote-backlinkReturn link to the reference (a).
.document .markdown-svelte-footnote {
	font-size: 0.85rem;
}

.document .markdown-svelte-footnote-reference-link {
	text-decoration: none;
}

HTML and fallbacks

Raw HTML is escaped by default. With allowRawHtml, sanitized HTML is rendered inside these wrappers. Its descendants do not receive Markdown classes; target their tags beneath your document class.

HTML and fallbacks selectors
SelectorElement
.markdown-svelte-html-blockSanitized HTML block wrapper (div).
.markdown-svelte-html-inlineSanitized inline HTML wrapper (span).
.markdown-svelte-html-escapedEscaped HTML source (span).
.markdown-svelte-fallbackRaw source for an unsupported node (span).
.document .markdown-svelte-html-block details {
	padding-block: 0.75rem;
	border-bottom: 1px solid #dce1d3;
}

.document .markdown-svelte-html-escaped {
	font-family: ui-monospace, monospace;
}

Streaming motion

Set these variables on your MarkdownStream class to adjust animation timing. Motion respects prefers-reduced-motion. For rendering without animation, use MarkdownRenderer from markdown-svelte with the same nodes array.

.document {
	--markdown-stream-fade-duration: 200ms;
	--markdown-stream-line-duration: 100ms;
	--markdown-stream-size-duration: 160ms;
	--markdown-stream-enter-duration: 140ms;
	--markdown-stream-media-duration: 160ms;
}
Streaming animation defaults
VariableDefaultApplies to
--markdown-stream-fade-duration280msAppended text and inline-code fades.
--markdown-stream-fade-easingcubic-bezier(0.33, 0, 0.67, 1)Appended text fade easing.
--markdown-stream-line-duration110msNew block lines, list items, cells, and atomic inline nodes.
--markdown-stream-line-easingcubic-bezier(0.25, 0.46, 0.45, 0.94)New line and item easing.
--markdown-stream-size-duration180msCode- and math-block height transitions.
--markdown-stream-size-easingcubic-bezier(0.25, 0.46, 0.45, 0.94)Height transition easing.
--markdown-stream-enter-duration160msContainer and thematic-break entrances.
--markdown-stream-enter-easingcubic-bezier(0.25, 0.46, 0.45, 0.94)Container and thematic-break easing.
--markdown-stream-media-duration180msImage reveal after loading.

Additional streaming classes

The renderer adds these classes for animated content. Prefer timing variables for motion changes. Code and math heights are calculated by the renderer; overriding their height, vertical padding, or overflow can interfere with sizing during a stream.

Additional streaming selectors
SelectorElement
.markdown-svelte-stream-deltaTemporary span around newly appended text.
.markdown-svelte-stream-list-itemAnimated list item.
.markdown-svelte-stream-definition-itemWrapper around a definition term and body.
.markdown-svelte-stream-footnoteAnimated footnote definition.
.markdown-svelte-stream-table-cellInner cell content wrapper.
.markdown-svelte-stream-math-blockAnimated block math.
.markdown-svelte-stream-code-size, .markdown-svelte-stream-math-sizeElements with managed height transitions.
.markdown-svelte-stream-block-enterBlockquote, admonition, and container entrance.
.markdown-svelte-stream-ruleThematic-break entrance.
.markdown-svelte-stream-code-languageLanguage label entrance.
.markdown-svelte-stream-image, .markdown-svelte-stream-image--loadedImage reveal and loaded state.

See the streaming guide for worker parsing and frame-paced state updates.