Skip to content

New Block: Dark Mode Toggle #42828

Closed
Closed

Description

@bhubbard

What problem does this address?

A simple block to let site visitors toggle between dark mode and light mode.

Activity

  1. added
    [Type] Enhancement
    [Status] Needs More Info
    on Jul 31, 2022
  2. ramonjd commented on Jul 31, 2022

    @ramonjd
    Member

    This could be useful, but might also be tricky to deliver in the plugin because it would be very difficult to guarantee that it would work for all themes.

    How would you see it working, especially in terms of styles?

  3. bhubbard commented on Aug 8, 2022

    @bhubbard
    Author

    @ramonjd I could see the default being the toggle, if there are multiple styles available then I could see a possible setting to allow it to be a dropdown that lets the user choose the style.

  4. scruffian commented on Aug 22, 2022

    @scruffian
    Contributor

    I think we'd need to add some tools for themes to be able to define "light" and "dark" colors.

  5. bhubbard commented on Aug 22, 2022

    @bhubbard
    Author

    I think we'd need to add some tools for themes to be able to define "light" and "dark" colors.

    @scruffian I agree, maybe this needs to be supported in theme.json for styles?

  6. github-actions commented on Sep 7, 2022

    @github-actions

    Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

  7. added
    [Status] Stale
    on Sep 7, 2022
  8. bhubbard commented on Sep 7, 2022

    @bhubbard
    Author

    Any suggestions on how to move this forward?

  9. ramonjd commented on Sep 7, 2022

    @ramonjd
    Member

    Isn't this already possible with global style variations?

    See: https://fullsiteediting.com/lessons/global-style-variations/

    Given that light/dark modes will be very theme-specific, it makes sense that a theme could have 2 x global style variations to cater.

  10. bhubbard commented on Sep 7, 2022

    @bhubbard
    Author

    Isn't this already possible with global style variations?

    See: https://fullsiteediting.com/lessons/global-style-variations/

    Given that light/dark modes will be very theme-specific, it makes sense that a theme could have 2 x global style variations to cater.

    A theme can have many styles. The original request is to have a dark mode/light mode toggle button block, such as this one for example: https://www.w3schools.com/howto/howto_js_toggle_dark_mode.asp

    This light mode/dark mode toggle is becoming more common across websites today. As a website visitor if my browser/os is set to dark mode, they may still wish to see the website in light mode. At the moment I don't think theme.json has a way to set a "style" as dark mode or light mode specific, nor does it support "prefer-color-scheme".

    Further Reading:

    Prefers Color Scheme

  11. removed
    [Status] Stale
    on Sep 8, 2022
  12. github-actions commented on Sep 24, 2022

    @github-actions

    Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

  13. added
    [Status] Stale
    on Sep 24, 2022
  14. Lewiscowles1986 commented on Oct 22, 2022

    @Lewiscowles1986
    Contributor

    Just a note that mainstream browsers have JS and CSS support for detecting the user preference on dark-mode.

    It's nothing but sparkling laziness to use a physical toggle if the default is not to respect the standards-based API's.

    I'm also not 100% sold that it matters if the editing experience needs to be in lock-step with the display presentation theme. There is a preview button if someone needs to see what content looks like on their frontend as a visitor would see it.

    I Created Automattic/blocks-everywhere#27 for Gutenberg outside of WordPress. Which presently describes a hack, which "works for me". This hack is predicated on the visual editor not being a WYSIWYG website editor; which honestly neither TinyMCE or Gutenberg are capable of achieving despite a lot of sunk effort and painful engineering to that end.

  15. 15 remaining items

  16. github-actions commented on Dec 28, 2022

    @github-actions

    Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

  17. added
    [Status] Stale
    on Dec 28, 2022
  18. removed
    [Status] Needs More Info
    [Status] Stale
    on May 30, 2023
  19. bhubbard commented on Jun 7, 2024

    @bhubbard
    Author
  20. Lewiscowles1986 commented on Jun 8, 2024

    @Lewiscowles1986
    Contributor

    So is this asking for a block for websites to add a toggle, or for Gutenberg itself to support dark-mode?

    All my posts were for the latter, not the former.

  21. bhubbard commented on Jun 10, 2024

    @bhubbard
    Author

    @Lewiscowles1986 So the original request is for a new toggle block. Browsing a lot of templates, I do see a lot of sites doing a drop-down that has light, dark, and system (default) as the options. And I feel this is probably best, as it defaults to system, but site visitors can then choose to see light and dark when they wish.

    Example:
    fb5a636f-f605-4ca3-b224-8a07c63d9912

    Based on the comments, I do see some work that may need to be completed first, such as let developers define "prefers-color-scheme" for color palette's set within the theme.json file. It might also make sense to have this as a site option stored in the wp_options table, with default being system, but allowing site owners to override the default for the site globally.

  22. Lewiscowles1986 commented on Jun 15, 2024

    @Lewiscowles1986
    Contributor

    @bhubbard are wp_options user-specific?
    I thought it was not https://codex.wordpress.org/Database_Description#Table:_wp_options

    To add complexity, I'm not 100% certain, that a user wanting dark-mode, would wish to do so for all of their devices.

  23. bhubbard commented on Jun 17, 2024

    @bhubbard
    Author

    @Lewiscowles1986 wp_options is not user-specific. But I was thinking its more for site owners to choose the default for their site, if they choose to not have it be "system". The idea being a user can always use this toggle or drop-down to then change on the front-end of the site.

  24. annezazu commented on Oct 12, 2025

    @annezazu
    Contributor

    Thanks for this discussion here. In reviewing this in light of a push for new blocks in Core #71026, I'm going to close this out as a duplicate of a broader issue here with more discussion #48249 As you can see in that discussion too, there is not a clear way forward nor easy solution for this to core. For now, check out https://developer.wordpress.org/news/2025/09/building-a-light-dark-toggle-with-the-interactivity-api/ which offers a way to do this for theme authors.

  25. Lewiscowles1986 commented on Oct 12, 2025

    @Lewiscowles1986
    Contributor

    @annezazu how can 42828 be a duplicate of 48249; the latter, was created nearly 1 year later.

    Thank you for linking it. As I see it, at least what I was hoping for wasn't captured in this issue or the new one.

  26. annezazu commented on Oct 12, 2025

    @annezazu
    Contributor

    Great question! When triaging and noticing similar issues, a judgement has to be made around what to keep open. Sometimes this means keeping open an issue that was created later but that, for whatever reason, has more traction and discussion. When that happens, in order to better preserve where momentum and context is (including the number of folks who’ve engaged and are following the issue), we’ll close the older issue. It’s ultimately a judgment call.

    With that context in mind, what is missing from the other issue? I see a clear reference to having a high contrast and dark mode.

  27. Lewiscowles1986 commented on Oct 13, 2025

    @Lewiscowles1986
    Contributor

    Thank you, for your answer, and patience.

    The other ticket is about implementing a block for end-users controlling the dark / light theme, as I believe this one may have originally been about.

    Missing for that use case would be respecting the system theme and what current or future wordpress mechanisms to leverage for that.

    I Should also create a separate issue for dark mode within the backend Gutenberg experience, but I don't know if there is any desire beyond my own for it; and I have a hack that gets me dark-mode looking Gutenberg.

  28. annezazu commented on Oct 13, 2025

    @annezazu
    Contributor

    Of course. Thanks for engaging so kindly.

    I Should also create a separate issue for dark mode within the backend Gutenberg experience, but I don't know if there is any desire beyond my own for it; and I have a hack that gets me dark-mode looking Gutenberg.

    Oh! At a broad level, this is being thought of right now with upcoming Admin Design efforts. Check out the parts around "Theming": #71196

    Missing for that use case would be respecting the system theme and what current or future wordpress mechanisms to leverage for that.

    I think this is where there's not a clear path forward for this as sites aren't applications and would likely need to be handled on a per site basis. It's complex, that's for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions