Skip to content

Replacing svg images in dark mode #8001

Closed Answered by slorber
monica-m-ps asked this question in General
Discussion options

You must be logged in to vote

If your SVG is an external .svg file, you can do:

import ThemedImage from '@theme/ThemedImage';

<ThemedImage
  alt="Docusaurus themed image"
  sources={{
    light: useBaseUrl('/img/docusaurus_light.svg'),
    dark: useBaseUrl('/img/docusaurus_dark.svg'),
  }}
/>;

https://docusaurus.io/docs/markdown-features/assets#github-style-themed-images


If you don't want to have duplicate .svg files, you can target SVG elements with custom CSS

svg.mySvg .mySvgPath {
  fill: red;
}

[data-theme='dark'] svg.mySvg .mySvgPath {
  fill: blue;
}

If your SVG is a React component you can do:

import React from 'react';
import {useColorMode} from '@docusaurus/theme-common';

export default function IconArrow(

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
8 replies
@felipecrs
Comment options

@slorber
Comment options

@felipecrs
Comment options

@tobi1220
Comment options

@slorber
Comment options

Answer selected by monica-m-ps
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants