Enhance the Chrome Address Bar Theme with Transition Effects for Color Changes

I've been working on implementing a dark mode feature on my website and it's been going smoothly. I have added a 0.3s ease transition for the theme change to make it more seamless. Additionally, I utilized the following JavaScript code to change the color of the address bar in Chrome for mobile:

//Changes the AddressBar Color!
window.document.querySelector(
  'meta[name="theme-color"]'
).setAttribute(
  'content', isDarkMode ? '#000000' : '#FFFFFF'
);
<!--In the Head Tag-->
<meta name="theme-color" content="#FFFFFF" />

Although everything is functioning correctly, I noticed that when I switch themes, the body color transitions gradually while the address bar color changes abruptly. How can I apply the same 0.3s ease color change to the address bar to maintain consistency throughout the transition?

I would greatly appreciate any assistance with this issue!

Answer №1

This solution activates a dark mode feature with just a button click. It includes a smooth dark mode animation that functions on mobile devices as well. Hopefully, this resolves your query. Feel free to let me know if it works for you.

var themeSwitch = document.querySelector('#color_scheme_switch');

function toggleTheme()
{
if(themeSwitch.checked){
 document.documentElement.setAttribute('data-color-scheme', 'dark');
 localStorage.setItem('color_scheme', 'dark');
}
else{
 document.documentElement.setAttribute('data-color-scheme', 'light'); 
 localStorage.setItem('color_scheme', 'light'); 
} 
  alert(document.documentElement.getAttribute('data-color-scheme'))
}

 themeSwitch.addEventListener('change', function(){ toggleTheme() });
/*font import*/
@import url('https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/*normalization*/
body{
  padding:0;
  margin:0;
  font-family:"Lato", Arial, Segoe UI, sans serif;
}

/*some fun*/
*{
  transition:color ease 0.2s, background-color ease 0.2s;
}

/*theme setup*/
:root{
--bg-color: #FAFAFA;
--text-color: #090909;
--anchor-color: #005AB3;
--highlight-color: #0066CC;
}

html[data-color-scheme = "dark"]{
--bg-color: #090909;
--text-color: #FAFAFA;
--anchor-color: #FFFFFF;
--highlight-color: #0099FF;
}

body{
 background-color: var(--bg-color);
 color: var(--text-color);
}

h1{
 color: var(--text-color);
}

::-moz-selection /* FireFox */
{
  color: var(--highlight-color);
  background: var(--highlight-bg);
}

::selection
{
  color: var(--highlight-color);
  background: var(--highlight-bg);
}

/*the Dark Mode Switch*/
label{
  position:absolute;
  right:20px;
  top:50%;
  --c:translate(-50%,-50%);
  transform:var(--c);
}

.switch{
  position:relative;
  left:0;top:0;
  width:40px;
  height:40px;
}

label > input{
  position:absolute;
  left:0;
  top:0;
  z-index:5;
  opacity:0;
  width:100%;
  height:100%;
}

.switch span{
  display:block;
  position:absolute;
  left:50%;
  top:50%;
  transform:var(--c);
  border-radius:50%;
  width:70%;
  height:70%;
  background:#FFAC33;
  border:5px solid white;
  transition:all ease 0.15s;
}

.switch div{
  position:absolute;
  left:0;top:0;
  width:100%;
  height:100%;
}

.switch div::before, .switch div::after{
  content:" ";
  display:block;
  position:absolute;
  left:50%;
  top:50%;
  transform:var(--c);
  background:#FFAC33;
  width:12%;
  height:130%;
  border-radius:10px;
  transition:all ease 0.15s;
}

.switch div:nth-child(1)::before{
  transform:var(--c) rotate(0deg);
}

.switch div:nth-child(1)::after{
  transform:var(--c) rotate(45deg); 
}

.switch div:nth-child(2)::before{
  transform:var(--c) rotate(90deg);
}

.switch div:nth-child(2)::after{
  transform:var(--c) rotate(135deg);
}

.switch::before, .switch::after{
  content:" ";
  position:absolute;
  left:50%;
  top:50%;
  transform:var(--c);
  border-radius:50%;
  background:white;
  transition:all ease 0.15s;
}

.switch::before{
  width:0%;
  height:0%;
  z-index:10;
}

.switch::after{
  width:50%;
  height:50%;
}

input:checked ~ .switch span{
    width:100%; 
    height:100%; 
    background:#66757F; 
}

input:checked ~ .switch div::before,
input:checked ~ .switch div::after{
    height:50%; 
}

input:checked ~ .switch::before{ 
    left:30%;
    top:30%;
    width:90%;
    height:90%;
}

input:checked ~ .switch::after{ 
    width:0%;
    height:0%;
}

input:not(:checked) ~ .switch{
    transform:rotate(180deg);
    transition:all ease 2.15s 0.1s;
}

/*other styles*/
main{
  line-height:1.4em;
}

.container, .post-container{
  position:relative;
}

.container{
  padding:40px;
}

.sticky{
  position:sticky;
  top:0;left:0;
  width:100%;
  height:80px;
  background-color:white;
  box-shadow:0 0 20px 0px rgba(0,0,0,0.4);
  z-index:100;
}

.stickytext{
  color:black;
  font-size:22px;
  position:absolute;
  left:30px;
  top:50%;
  transform:translateY(-50%);
  padding-bottom:5px;
}
<div class="sticky">
 <div class="stickytext">Click the moon</div>
 <label>
  <input id="color_scheme_switch" type="checkbox" aria-label="Turn off the lights!" title="Switch to Dark Mode"/>
  <div class="switch">
   <div></div>
   <div></div>
   <span></span>
  </div>
 </label>
</div>

<div class="container">
  <h1>Lorem Ipsum Dolor Sit Amet.</h1>
  <main class="post-content">
   This is where your main post content would go.
  </main>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling with smoothly transitioning an image into view using CSS and JavaScript

I'm currently experimenting with creating a cool effect on my website where an image fades in and moves up as the user scrolls it into view. I've included the code I have so far below, but unfortunately, I keep getting a 404 error when trying to ...

Having trouble implementing the FCKeditor in a Zend form

I am trying to integrate FCKeditor with my form by downloading the CKeditor library from Although everything seems to be working fine, I keep encountering the following error: ReferenceError: ReferenceError: CKeditor is not defined Here is the JavaScri ...

Tips on configuring the path to incorporate Bootstrap CSS, JavaScript, and font files/classes into HTML when the HTML file and Bootstrap files are located in different directories

<!DOCTYPE html> <html> <head> <title>Unique Demo</title> <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen"> </head> <body> <div class="container"> <form ...

Switch Slide Title with jQuery in Cycle2 Plugin

Looking for a simple solution as the week comes to an end. I'm currently using Cycle2 to create an image slider. While C2 allows for transitioning captions based on the slide, it doesn't seem to support transitioning other elements. In my case, ...

Dynamically using jQuery, a table with alternating rows contains a select box in the background color

I have a table with rows that include select boxes. I want to apply alternating colors to the rows, but the select boxes aren't changing color. How can I achieve this? HTML <table width="100%" cellpadding="0" cellspacing="0" border="0" class="std ...

The Horizontal Tab Character in Unicode

I am encountering a situation where I have a function that stores a string read off a StreamReader. The file being read contains horizontal tabs encoded as U+0009 in Unicode. My goal is to display this string in HTML, which requires some conversion. Here ...

Having trouble with Express router behaving unexpectedly in a subdirectory

In my Node.js app, I have organized my API queries by modules. This structure is reflected in the index.js file as follows: app.use('/api/schedule/', apiSchedule); Within the apiSchedule router, I have defined different route handlers: router. ...

Create a new URL redirection while clearing the previous URL from the browsing history

Is there a way to replace the current URL document with a new one in PHP without storing the original URL in the browser history or allowing the user to navigate back using the "back" button? I know this can be achieved using jQuery or JavaScript by utili ...

Achieving precise alignment of div content through Css techniques

body { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #333; } .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: ...

Splitting columns evenly in a table with a width of 100%

Welcome to my first query on this platform. Despite my efforts to search for a solution, I couldn't find an explanation as to why my code isn't functioning correctly in Internet Explorer (10+). I have created three divs displayed as cells, each ...

The connection between the Node.js server and React.js client is not working properly with Socket.io

My goal is to establish a socket.io connection between an express server and a react client. It's worth mentioning that the client is hosted on netlify and the server is on heroku. The issue I'm facing is that the client appears to connect and re ...

Arrange records in ascending order by phone number when multiple are returned on the same date

Currently, I am working on an Angular application that is designed to keep track of tuxedo rentals. The main feature of the app is a table that displays information from an array stored in the controller. The initial task I completed was listing the items ...

Enhancing the Google canvas script to incorporate numerous markers

Currently, I am using a template that includes a Google map with coordinates set in JavaScript. The code for the marker on the map is as follows: //Google Map var latlng = new google.maps.LatLng(44.761128,21.227395); var settings = { ...

The API response indicating success is simply denoted as "Success: True", without any accompanying data

I've set up my application on an express server with a proxy to communicate with the API server. Here's a snippet of my code: HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> ...

What steps are involved in setting up a single form for entering orders, complete with both an order table and an order_item table that incorporates a foreign key

As I contemplate the best way to structure my page and forms for a customer ordering process, a few questions arise due to the tables' organization. To adhere to normalization standards, I have separated the order table and the order items table, link ...

Error: Unable to Start Session - This ChromeDriver version is only compatible with Chrome version 81, causing the session creation to fail

Just starting out with robot framework and running into a Chrome version issue. I'm using the latest window version of Chrome and chromedriver, which is 80. However, when trying to run the test in PyCharm, I keep getting the error message "SessionNotC ...

When trying to access the key value of a dynamically generated object, it returns as undefined

I am facing a challenge with my student object structure... { Freshmen: [{id: 3}, {id: 5}], Sophomores: [{id: 2}, {id: 6}], Juniors: [{id: 1}, {id: 8}], Seniors: [{id: 9}, {id: 4}, {id: 7}] } My goal is to retrieve full student objects from the d ...

Configuring user limitations within a LAMP application

There are three tables in the database (details_letter Table, Address_details Table, and Signatories Table) that display what each user saves. Currently, when the Manager, HR, and Legal Officer are logged in, they can view each others' saved content. ...

Using an Angular dynamic ng-model name within an accordion

Looking for a way to make the ng-model name dynamic in this specific situation. Whenever a department is selected, the form needs to be updated accordingly. Currently, it works with ng-model="department.name", but this is causing some unexpected issues du ...

What could be causing chromedriver to fail to launch the website?

Currently facing an issue: Unable to open any page URL in Chrome using simple code. The Chrome window pops up asking which user is currently using Chrome, allowing the selection of profiles. However, it quickly disappears causing errors in my program. imp ...