Skip to content

Commit 7908977

Browse files
authored
fix: give SVG images a white background in dark mode (#642)
We recently introduced dark mode. SVG images often have dark text on transparent backgrounds, making them invisible when the page background is dark. As a workaround, add a white backdrop via CSS on SVGs (by file extension). There may be better fixes here, but this works well in my testing and requires no action from contributors (e.g. multiple images). Before/after: <img width="913" height="427" alt="image" src="https://github.com/user-attachments/assets/9fd6fbf5-c609-45f8-a8a8-581e2889b651" /> <img width="913" height="427" alt="image" src="https://github.com/user-attachments/assets/97bd46ba-2d02-4b05-9dd2-56e021040245" />
1 parent 113a75b commit 7908977

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

_sass/modules/_dark-mode.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@
142142
border-radius: 4px;
143143
padding: 2px;
144144
}
145+
146+
// SVG diagrams commonly have dark text on transparent backgrounds, which
147+
// becomes invisible against the dark page background. Give them a white
148+
// backdrop. Targets only SVGs (diagrams), not photos (jpg/png).
149+
article .content img[src$=".svg"] {
150+
background-color: white;
151+
border-radius: 4px;
152+
padding: 4px;
153+
}
145154
}
146155

147156
// System preference: apply dark theme only when no explicit choice is saved.

0 commit comments

Comments
 (0)