<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vinay</title>
    <description>The latest articles on DEV Community by Vinay (@vinay_5d249e669fb47d24e2c).</description>
    <link>https://dev.to/vinay_5d249e669fb47d24e2c</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3600948%2Fca01f8e3-f002-41d7-af8c-01197e921429.png</url>
      <title>DEV Community: Vinay</title>
      <link>https://dev.to/vinay_5d249e669fb47d24e2c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vinay_5d249e669fb47d24e2c"/>
    <language>en</language>
    <item>
      <title>Stop Inverting Your Colors: The Modern Way to Implement Dark &amp; Light Mode</title>
      <dc:creator>Vinay</dc:creator>
      <pubDate>Fri, 07 Nov 2025 11:09:00 +0000</pubDate>
      <link>https://dev.to/vinay_5d249e669fb47d24e2c/stop-inverting-your-colors-the-modern-way-to-implement-dark-light-mode-4p2d</link>
      <guid>https://dev.to/vinay_5d249e669fb47d24e2c/stop-inverting-your-colors-the-modern-way-to-implement-dark-light-mode-4p2d</guid>
      <description>&lt;p&gt;Hey Devs! Let's Talk Dark Mode.&lt;br&gt;
If you're building a website today, adding a Dark Mode isn't just a cool feature—it's practically mandatory. It's an accessibility win, and frankly, people just prefer it when they're coding at 2 AM.&lt;/p&gt;

&lt;p&gt;But we need to stop just slapping an filter: invert(100%) on the whole page. That looks awful. We want a smooth, custom, and professional switch.&lt;/p&gt;

&lt;p&gt;This post will show you the three simple steps to build a robust theme system using CSS Variables, respecting your user's OS preference, and adding that satisfying toggle button.&lt;/p&gt;

&lt;p&gt;Step 1: CSS Variables are Your Best Friends 🎨&lt;br&gt;
The secret sauce here is CSS Custom Properties (aka variables). Instead of defining colors like "blue" or "black," we define them by their function. That way, we only have to change the variable values once to switch the whole theme!&lt;/p&gt;

&lt;p&gt;Check out this structure for your main CSS:&lt;/p&gt;

&lt;p&gt;CSS&lt;/p&gt;

&lt;p&gt;/* LIGHT THEME: The default. Defined in the main :root &lt;em&gt;/&lt;br&gt;
:root {&lt;br&gt;
  --color-bg-primary: #ffffff;      /&lt;/em&gt; Main background is white &lt;em&gt;/&lt;br&gt;
  --color-text-primary: #121212;     /&lt;/em&gt; Text is a dark gray &lt;em&gt;/&lt;br&gt;
  --color-accent: #007bff;          /&lt;/em&gt; Standard blue for links &lt;em&gt;/&lt;br&gt;
  --shadow-default: rgba(0, 0, 0, 0.1); /&lt;/em&gt; Light, subtle shadow */&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;/* DARK THEME: Overwrite the variables inside a data-theme attribute &lt;em&gt;/&lt;br&gt;
[data-theme="dark"] {&lt;br&gt;
  --color-bg-primary: #1e1e1e;      /&lt;/em&gt; Main background is deep gray &lt;em&gt;/&lt;br&gt;
  --color-text-primary: #f9f9f9;     /&lt;/em&gt; Text is near-white &lt;em&gt;/&lt;br&gt;
  --color-accent: #8ab4f8;          /&lt;/em&gt; Lighter blue that pops on dark &lt;em&gt;/&lt;br&gt;
  --shadow-default: rgba(255, 255, 255, 0.05); /&lt;/em&gt; Very subtle white shadow */&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;/* Usage - this never changes, only the variable value does! &lt;em&gt;/&lt;br&gt;
body {&lt;br&gt;
  background-color: var(--color-bg-primary);&lt;br&gt;
  color: var(--color-text-primary);&lt;br&gt;
  transition: background-color 0.3s, color 0.3s; /&lt;/em&gt; Don't forget the smooth transition! */&lt;br&gt;
}&lt;br&gt;
Pro Tip: Avoid pure black (#000) and pure white (#fff). The contrast is painful in Dark Mode. Use softer dark grays and near-white colors for a much gentler look.&lt;/p&gt;

&lt;p&gt;Step 2: Honor the User's System Preference 🖥️&lt;br&gt;
If someone's OS is already set to Dark Mode, we should respect that immediately on page load to prevent a nasty FOUC (Flash of Unstyled Content). We need to do this with a tiny bit of JavaScript before the rest of the page loads.&lt;/p&gt;

&lt;p&gt;Place this script right after your opening &lt;/p&gt; tag:

&lt;p&gt;HTML&lt;/p&gt;

&lt;p&gt;const storageKey = 'theme-preference';&lt;/p&gt;

&lt;p&gt;function getTheme() {&lt;br&gt;
    // 1. Check for manual choice (saved in storage)&lt;br&gt;
    const storedTheme = localStorage.getItem(storageKey);&lt;br&gt;
    if (storedTheme) return storedTheme;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 2. Fall back to the OS setting
return window.matchMedia('(prefers-color-scheme: dark)').matches
  ? 'dark'
  : 'light';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// Set the initial theme right away on the &amp;lt;html&amp;gt; element&lt;br&gt;
  document.documentElement.setAttribute('data-theme', getTheme());&lt;/p&gt;

&lt;p&gt;This script ensures the user sees the right theme instantly, preventing that annoying white flash if they prefer dark.&lt;/p&gt;

&lt;p&gt;Step 3: Add the Toggle Button 🌙&lt;br&gt;
Users love having control. Let's add a simple button to override the system setting and, critically, save their preference in localStorage.&lt;/p&gt;

&lt;p&gt;HTML for the Toggle:&lt;/p&gt;

&lt;p&gt;HTML&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
  &lt;span&gt;🌓&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
JavaScript for the Logic:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;/p&gt;

&lt;p&gt;document.addEventListener('DOMContentLoaded', () =&amp;gt; {&lt;br&gt;
  const toggleButton = document.getElementById('theme-toggle');&lt;br&gt;
  const storageKey = 'theme-preference'; // Re-use the key from the script above!&lt;/p&gt;

&lt;p&gt;const setTheme = (theme) =&amp;gt; {&lt;br&gt;
    document.documentElement.setAttribute('data-theme', theme);&lt;br&gt;
    localStorage.setItem(storageKey, theme);&lt;br&gt;
  };&lt;/p&gt;

&lt;p&gt;toggleButton.addEventListener('click', () =&amp;gt; {&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepkdduiru0083gcdmq0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepkdduiru0083gcdmq0z.png" alt=" " width="800" height="639"&gt;&lt;/a&gt;/ Get the &lt;em&gt;current&lt;/em&gt; theme from the HTML attribute&lt;br&gt;
    const currentTheme = document.documentElement.getAttribute('data-theme');&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Determine the new theme
const newTheme = currentTheme === 'light' ? 'dark' : 'light';

setTheme(newTheme);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;br&gt;
});&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Just launched my personal portfolio built with Framer! Showcasing my work in web design, HTML, CSS, JavaScript &amp; SEO. Check it out here: https://vinaygujjetiportfolio.framer.website
#WebDesign, #FrontendDevelopment, #HTML, #CSS, #JavaScript &amp; #SEO</title>
      <dc:creator>Vinay</dc:creator>
      <pubDate>Fri, 07 Nov 2025 10:51:58 +0000</pubDate>
      <link>https://dev.to/vinay_5d249e669fb47d24e2c/just-launched-my-personal-portfolio-built-with-framer-showcasing-my-work-in-web-design-html-css-3gmp</link>
      <guid>https://dev.to/vinay_5d249e669fb47d24e2c/just-launched-my-personal-portfolio-built-with-framer-showcasing-my-work-in-web-design-html-css-3gmp</guid>
      <description>&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://vinaygujjetiportfolio.framer.website/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fframerusercontent.com%2Fassets%2Fpvk0lsytPhDLZNAfWFZtlC9GWM.png" height="367" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://vinaygujjetiportfolio.framer.website/" rel="noopener noreferrer" class="c-link"&gt;
            Website Developer in Hyderabad | Web Developer – Vinay Gujjeti
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Looking for a Website Developer in Hyderabad? Explore the portfolio of Vinay Gujjeti – Web Developer skilled in HTML, CSS, JavaScript, WordPress &amp;amp; Bootstrap
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fframerusercontent.com%2Fimages%2F6HhLDNLhbO9IVWnX36kuSZ1z4c.png" width="100" height="100"&gt;
          vinaygujjetiportfolio.framer.website
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
  </channel>
</rss>
