Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dark and light variants for images #2947

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/empty-beds-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': minor
---

Make light and dark image variants
12 changes: 12 additions & 0 deletions docs/src/content/docs/guides/authoring-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ Relative image paths are also supported for images stored locally in your projec
![A rocketship in space](../../assets/images/rocket.svg)
```

### Light and dark variants

If you want to show different images for light and dark color schemes, you can append a `#only-light` or `#only-dark` hash fragment to the image URL:

```md
![Image for the light theme](../../assets/light-logo.svg#only-light)
![Image for the dark theme](../../assets/dark-logo.svg#only-dark)
```

![Image for the light theme](https://github.com/user-attachments/assets/5ff75483-d761-4dbd-b3a0-c7823b137ec5#only-light)
![Image for the dark theme](https://github.com/user-attachments/assets/ab396486-d6a3-41ac-85ff-a961f319fbca#only-dark)

## Headings

You can structure content using a heading. Headings in Markdown are indicated by a number of `#` at the start of the line.
Expand Down
6 changes: 6 additions & 0 deletions packages/starlight/style/util.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
[data-theme='dark'] .dark\:sl-hidden {
display: none;
}
[data-theme='light'] img[src$="#only-dark"] {
display: none;
}
[data-theme='dark'] img[src$="#only-light"] {
display: none;
}

/*
Flip an element around the y-axis when in an RTL context.
Expand Down