Skip to content

Commit 45f434f

Browse files
docs: document auto theme change #2074 (#2229)
* Document auto theme change in README #2074 * Document auto theme change in README Document auto theme change in README #2074 (update-1) * Document auto theme change updates #2074 * docs: improve dynamic theme documentation Co-authored-by: rickstaa <[email protected]>
1 parent 199870a commit 45f434f

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

readme.md

+90
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Visit <https://indiafightscorona.giveindia.org> and make a small donation to hel
8585
- [Top Languages Card](#top-languages-card)
8686
- [Wakatime Week Stats](#wakatime-week-stats)
8787
- [Themes](#themes)
88+
- [Responsive Card Theme](#responsive-card-theme)
8889
- [Customization](#customization)
8990
- [Common Options](#common-options)
9091
- [Stats Card Exclusive Options](#stats-card-exclusive-options)
@@ -156,6 +157,95 @@ GitHub readme stats comes with several built-in themes (e.g. `dark`, `radical`,
156157

157158
You can look at a preview for [all available themes](./themes/README.md) or checkout the [theme config file](./themes/index.js) & **you can also contribute new themes** if you like :D
158159

160+
#### Responsive Card Theme
161+
162+
[![Anurag's GitHub stats-Dark](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark#gh-dark-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-dark-mode-only)
163+
[![Anurag's GitHub stats-Light](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=default#gh-light-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-light-mode-only)
164+
165+
Since GitHub will re-upload the cards and serve them from their [CDN](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-anonymized-urls), we can not infer the browser/GitHub theme on the server side. There are, however, four methods you can use to create dynamics themes on the client side:
166+
167+
##### Use the transparent theme
168+
169+
We have included a `transparent` theme that has a transparent background. This theme is optimized to look good on GitHub's dark and light default themes. You can enable this theme using the `&theme=transparent` parameter like so:
170+
171+
```md
172+
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=transparent)
173+
```
174+
175+
<details>
176+
<summary>:eyes: Show example</summary>
177+
178+
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=transparent)
179+
180+
</details>
181+
182+
##### Add transparent alpha channel to a themes bg_color
183+
184+
You can use the `bg_color` parameter to make any of [the available themes](./themes/README.md) transparent. This is done by setting the `bg_color` to a colour with a transparent alpha channel (i.e. `bg_color=00000000`):
185+
186+
```md
187+
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&bg_color=00000000)
188+
```
189+
190+
<details>
191+
<summary>:eyes: Show example</summary>
192+
193+
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&bg_color=00000000)
194+
195+
</details>
196+
197+
##### Use GitHub's theme context tag
198+
199+
You can use [GitHub's theme context](https://github.blog/changelog/2021-11-24-specify-theme-context-for-images-in-markdown/) tags to switch the theme based on the user GitHub theme automatically. This is done by appending `#gh-dark-mode-only` or `#gh-light-mode-only` to the end of an image URL. This tag will define whether the image specified in the markdown is only shown to viewers using a light or a dark GitHub theme:
200+
201+
```md
202+
[![Anurag's GitHub stats-Dark](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark#gh-dark-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-dark-mode-only)
203+
[![Anurag's GitHub stats-Light](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=default#gh-light-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-light-mode-only)
204+
```
205+
206+
<details>
207+
<summary>:eyes: Show example</summary>
208+
209+
[![Anurag's GitHub stats-Dark](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark#gh-dark-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-dark-mode-only)
210+
[![Anurag's GitHub stats-Light](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=default#gh-light-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-light-mode-only)
211+
212+
</details>
213+
214+
##### Use GitHub's new media feature
215+
216+
You can use [GitHub's new media feature](https://github.blog/changelog/2022-05-19-specify-theme-context-for-images-in-markdown-beta/) in HTML to specify whether to display images for light or dark themes. This is done using the HTML `<picture>` element in combination with the `prefers-color-scheme` media feature.
217+
218+
```html
219+
<picture>
220+
<source
221+
srcset="https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark"
222+
media="(prefers-color-scheme: dark)"
223+
/>
224+
<source
225+
srcset="https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true"
226+
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
227+
/>
228+
<img src="https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true" />
229+
</picture>
230+
```
231+
232+
<details>
233+
<summary>:eyes: Show example</summary>
234+
235+
<picture>
236+
<source
237+
srcset="https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark"
238+
media="(prefers-color-scheme: dark)"
239+
/>
240+
<source
241+
srcset="https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true"
242+
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
243+
/>
244+
<img src="https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true" />
245+
</picture>
246+
247+
</details>
248+
159249
### Customization
160250

161251
You can customize the appearance of your `Stats Card` or `Repo Card` however you wish with URL parameters.

0 commit comments

Comments
 (0)