<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
  <channel>
    <title>nev.nya.je (the coding guides)</title>
    <link>https://nev.nya.je/</link>
    <atom:link href="https://nev.nya.je/guides/guides.xml" rel="self" type="application/rss+xml"/>
    <description>Coding guides of.nev.nya.je</description>
    <lastBuildDate>Thu, 29 Oct 2026 17:50:55 GMT</lastBuildDate>
    <language>en</language>
    <generator>Lume 3.3.2</generator>
    <author>
      <name>Nev</name>
      <uri>https://nev.nya.je</uri>
    </author>
    <item>
      <title>Classless Image Positioning</title>
      <link>https://nev.nya.je/guides/classless-img-positioning/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/classless-img-positioning/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>Did you know you could position an image between paragraphs with a hashtag?</description>
      <content:encoded>
        <![CDATA[<p>A while back, I struggled with centering an <code>img</code> between blocks of paragraphs for my blog posts. I eventually found the solution on StackOverflow, but I forgot to bookmark the link and now I lost the source! It was so game-changing that I don't want to go back to making <code>.center</code> class again.</p>
<p>This was the accepted answer:</p>
<pre><code class="language-css">img[src*=&quot;#center&quot;] {
    display: block;
    margin: auto;
}
</code></pre>
<p>This is called attribute selector. <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/Attribute_selectors">Quoting from MDN</a>, this selector matches the HTML attribute defined inside the brackets. The code above says to target any <code>img</code> whose <code>src</code> contains <code>&quot;#center&quot;</code>.</p>
<p>To make it work, insert an <code>img</code> into your HTML file and add <code>#center</code> in the <code>src</code> like this:</p>
<pre><code class="language-html">&lt;img src=&quot;path/to/your/image.jpg#center&quot; alt=&quot;alt text&quot; loading=&quot;lazy&quot;&gt;
</code></pre>
<p>Here's the result!</p>
<figure><img src="https://file.garden/acMMxqtw6Rf7Qz6n/tanimura_icon.png#center" alt="Tanimura" loading="lazy" decoding="async"></figure>
<p>I really love this approach because it's so, so clean and you don't need to create a class to make it work. If you use an SSG, this also works on Markdown files. It doesn't affect the image link.</p>
<p>You can also place images on the left or right side of a paragraph the same way.</p>
<pre><code class="language-css">img {
    display: flex;
}

img[src*=&quot;#left&quot;] {
  float: left;
}

img[src*=&quot;#right&quot;] {
  float: right;
}
</code></pre>
<p>Below is how it looks like in image-text-image-text order:</p>
<figure><img src="https://file.garden/acMMxqtw6Rf7Qz6n/tanimura_icon.png#left" alt="Tanimura" loading="lazy" decoding="async"></figure>
<p>Aenean elementum in velit at interdum. Nulla rutrum non lorem a tempus. Fusce nisl ligula, venenatis at ante eu, sodales iaculis justo. Vivamus vitae neque mollis, fermentum nisl sed, sagittis neque. Donec dapibus odio in turpis fringilla mattis. Praesent turpis lorem, efficitur semper hendrerit quis, finibus vitae sapien. Nulla a rutrum nulla.</p>
<figure><img src="https://file.garden/acMMxqtw6Rf7Qz6n/tanimura_icon.png#right" alt="Tanimura" loading="lazy" decoding="async"></figure>
<p>Integer fringilla dignissim erat, a fermentum eros vulputate quis. Aliquam nec quam ullamcorper, imperdiet erat in, pretium erat. Duis vel diam et orci fermentum egestas. Nullam aliquam urna eget libero tempor, ut porta turpis fermentum. Suspendisse sit amet pulvinar diam, non facilisis dolor. Morbi tincidunt purus eget lacus mattis mattis. Pellentesque in ex pellentesque, bibendum libero quis, faucibus nisl. Phasellus eu efficitur purus, a fringilla turpis.</p>
<p>I hope it helps somebody out there.</p>
]]>
      </content:encoded>
      <pubDate>Mon, 26 Oct 2026 00:00:00 GMT</pubDate>
    </item>
    <item>
      <title>Light and Dark Mode with Only CSS</title>
      <link>https://nev.nya.je/guides/light-dark-mode/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/light-dark-mode/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>Easy peasy light and dark mode theming with prefers-color-scheme.</description>
      <content:encoded>
        <![CDATA[<p>I've been looking for ways to have light and dark colour scheme for my site, preferably
without JavaScript, then I found this <a href="https://blog.tymek.dev/no-js-dark-mode-toggle/">simple CSS-only theme toggle guide by tymek.dev</a>.</p>
<p>Unfortunately after messing with it for a bit, the method didn't suit my use case. It's because the radio check state isn't saved globally. That means user will have to manually switch the theme every time they move pages, and I will have to add this toggle all over my site. Not so efficient.</p>
<p>So I made a guide on how I did my light and dark colour scheme by using <code>:root</code> pseudo-class and <code>prefers-color-scheme</code> media at-rule. Even if you're a complete beginner, you can do it too!</p>
<h2>Step 1: Set a colour palette with <code>:root {}</code></h2>
<p>This not necessary, but using <code>:root {}</code> pseudo-class lets you declare a set of custom variables that can be used globally across your CSS files. With this, you no longer need to manually give hex colour codes to each property value and you can change multiple property values from one variable. Custom variables use a precending double dash <code>--</code>.</p>
<pre><code class="language-css">:root {
  --text: black;
  --background: white;
}
</code></pre>
<p>Besides hex colour codes, you can also create shorthands for other property
values, like this <code>--border: 2px solid grey;</code>, or this
<code>--shadow: 1px 1px 3px #00000080, -1px -1px 3px #00000080;</code>, or even this
<code>--defaultFont: 'Iosevka', monospace;</code>.</p>
<p>You can put the global variables within your main CSS file or in an external
file.</p>
<p>If you declare these global variables within the same CSS file, you can use them
like this:</p>
<pre><code class="language-css">body {
  color: var(--text);
  background: var(--background);
}
</code></pre>
<p>Or if you declare them externally, you can use <a href="https://nev.nya.je/guides/@import/">@import</a> to
link the file to another where you need to access these global variables.</p>
<pre><code class="language-css">@import url(global.css);

body {
  color: var(--text);
  background: var(--background);
}
</code></pre>
<h2>Step 2: Use <code>@media (prefers-color-scheme)</code></h2>
<p>Once you're done setting up your palette, we can add <code>@media (prefers-color-scheme)</code> at the
bottom of the CSS file. This is so there won't be any conflicting rules and
properties, because CSS reads from top to bottom (that's how it gets the
'cascading' in Cascading Style Sheets :P).</p>
<p>Depending on your needs, you can set the value in
<code>@media (prefers-color-scheme)</code> to either <code>dark</code> or <code>light</code>. The browser will default itself to seeing your site in <code>light</code> mode if it can't find any <code>prefers-color-scheme: dark;</code> rules in your CSS files or if a visitor has no preferred colour scheme. So, any rules you've set in the CSS are presumed to be <code>light</code> colour scheme.</p>
<p>As an example, let's try switching the text colour and background of <code>body</code> in
dark mode. We can place <code>@media (prefers-color-scheme: dark)</code> rule after we declare the rules of <code>body</code>, like this:</p>
<pre><code class="language-css">body {
  color: black;
  background: white;
}

@media (prefers-color-scheme: dark) {
  body {
    color: white;
    background: black;
  }
}
</code></pre>
<p>Anything inside the <code>@media (prefers-color-scheme: dark)</code> at-rule will be
applied when visitor requests a dark mode of your site, so you're meant to redeclare/rewrite all important elements you wish to be adaptive here.</p>
<h2>Step 2.5: Make some adjustments</h2>
<p>Converting one theme to another requires you to also change graphical properties. <code>@media (prefers-color-scheme)</code> doesn't limit you from changing <em>only</em> colours. Consider the following scenarios:</p>
<h3>Change backgrounds or any image value properties in dark mode</h3>
<p>An element using an image as a background may look blinding in dark mode. Can you change that? You can, by giving an alternate <code>background</code> inside <code>@media (prefers-color-scheme: dark)</code>!</p>
<pre><code class="language-css">.container {
	background: url('brightbackground.jpg');
}

@media (prefers-color-scheme: dark) {
	.container {
		background: url('darkbackground.jpg');
	}
}
</code></pre>
<p>And before you know it, you'll achieve something like this!</p>
<figure><img src="https://nev.nya.je/guides/assets/light-dark-mode-01.jpg#center" alt="My yumeclique widget in light and dark mode, each having different background image" loading="lazy" decoding="async"></figure>
<h3>Get rid of something with <code>display:none;</code></h3>
<p>Let's say there's an element that doesn't look good in one colour scheme and
you want it to visually disappear. You can use <code>display: none</code> to hide this
pesky element inside your preferred colour scheme at-rule.</p>
<p>My use case: the iMood widget.</p>
<figure><img src="https://nev.nya.je/guides/assets/light-dark-mode-02.jpg#center" alt="Comparisons between my iMood widgets in light mode and dark mode" loading="lazy" decoding="async"></figure>
<p>Both widgets act like an image, so there's no way for me to change the colour and background automatically. With <code>display: none</code>, I can make them act like it changes colour upon switching themes!</p>
<p>Here's the HTML code:</p>
<pre><code class="language-html">&lt;p&gt;
I was 
	&lt;a href=&quot;https://www.imood.com/users/nev&quot; 
	class=&quot;imood light&quot;&gt;
		&lt;img src=&quot;https://moods.imood.com/display/uname-nev/trans-1/imood.gif&quot; 
		alt=&quot;The current mood of nev at www.imood.com&quot; border=&quot;0&quot;&gt;
	&lt;/a&gt; 
	&lt;a href=&quot;https://www.imood.com/users/nev&quot; 
	class=&quot;imood dark&quot;&gt;
		&lt;img src=&quot;https://moods.imood.com/display/uname-nev/fg-ededed/trans-1/imood.gif&quot; 
		alt=&quot;The current mood of nev at www.imood.com&quot; border=&quot;0&quot;&gt;
	&lt;/a&gt;
&lt;/p&gt;
</code></pre>
<p>And here's the CSS:</p>
<pre><code class="language-css">a.imood.light {
	display: inline;
}

a.imood.dark {
	display: none;
}

@media (prefers-color-scheme: dark) {
	a.imood.light {
		display: none;
	}

	a.imood.dark {
		display: inline;
	}
}
</code></pre>
<p>Using this doesn't remove the other element from the source code and the document tree, of course. Screen readers, or people viewing your site from page source (<kbd>Ctrl</kbd> + <kbd>U</kbd>) can still see there are two widgets in the same paragraph.</p>
<p><em>&quot;Why not set a background on the iMood's website?&quot; Shh!</em></p>
<h2>Step 3: Preview using Inspect Mode</h2>
<p>Now you might be thinking, &quot;Ugh, should I switch colour scheme from my browser settings just to see how it looks like?&quot;</p>
<p>No need! The Inspect Element feature in your browser allows you to simulate between colour schemes. You can do so by pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>I</kbd>.</p>
<figure><img src="https://nev.nya.je/guides/assets/light-dark-mode-03.png#center" alt="Inspect Element feature, seen in Zen" loading="lazy" decoding="async"></figure>
<p>In the Inspector tab, you'll find two buttons to simulate dark and light mode, located just above the style inspector. Simply press one of the buttons and it'll automatically apply the rules for you.</p>
<figure><img src="https://nev.nya.je/guides/assets/light-dark-mode-04.png#center" alt="Accessibility inspector in Inspect Element" loading="lazy" decoding="async"></figure>
<p>Another feature in Inspect Element I strongly recommend using is the <strong>Accessibility tab</strong>. This lets you check for any accessibility-related issues, including <strong>colour constrast</strong>, and it will warn you if a contrast score doesn't meet the <abbr title="Web Content Accessibility Guidelines.">WCAG</abbr> standard.</p>
<h2>Pros and Cons of Using Only CSS</h2>
<p>The benefits of using only CSS to achieve this is you're giving options on how your visitors wish to see your site depending on their device settings without relying on JavaScript.</p>
<p>Of course, this flexibility comes with a downside: there won't be a theme toggle on the site, so users have no choice but to change the theme from their browser settings.</p>
]]>
      </content:encoded>
      <pubDate>Wed, 16 Sep 2026 00:00:00 GMT</pubDate>
    </item>
    <item>
      <title>CSS Attribute Selector and Pseudo-elements</title>
      <link>https://nev.nya.je/guides/css-attr/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/css-attr/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>
        From automatically adding arrows to external links to adding 'new' next to your newest blog post title, you can take advantage of these things.
      </description>
      <content:encoded>
        <![CDATA[<p>Ages ago, I was busy editing <span class="devoted">Devoted</span> (my other <a href="https://devoted.nekoweb.org/">site</a>) and was figuring out how to let visitors know that some links are external links. My first instinct was to put the arrow emoji/symbol inside my <code>a</code> tag like so: <code>&lt;a href=&quot;example.com&quot;&gt;demo site ↗&lt;/a&gt;</code>. I did this for a solid three months until I found Mouseling's post explaining that I can add those arrows <em>automatically</em> with CSS. How does one do this? By relying on CSS attribute selector and pseudo-element!</p>
<p>From there on, I kinda fell down the rabbit hole and enjoyed using them a bit too much. In this guide, I'd like to demonstrate a few things you can do with attribute selector, along with pseudo-elements.</p>
<p><em>This guide is inspired by <a href="https://mouseling.net/posts/2025-08-09-outlinks">Mouseling</a>'s post. I suggest reading their guide for a shorter, simpler explanation.</em></p>
<h2>Demo #1: Automatically Add Arrows to External Links</h2>
<blockquote>
<p>One of HTML's best practises is <a href="https://www.w3.org/WAI/WCAG21/Techniques/general/G200">to give context to links, whether it's an external or internal link</a>.</p>
</blockquote>
<p>The above link will take you to a W3C article. The arrow indicates an external link and I use it to tell visitors that should you click on that link, it will take you to a different site. Of course, one can easily achieve this by adding arrow (<code>↗</code>) between your <code>a</code> tags, but what if there are way too many external links?</p>
<p>An easy way is to use CSS attribute selector and the pseudo-element <code>::after</code> this way:</p>
<pre><code class="language-css">a[href^=&quot;http&quot;]::after {
	content: &quot;↗&quot;;
	padding-left: 3px;
	display: inline-block;
}

/* Below is if you use nested CSS: */

a {
	color: #8F4300;
	&amp;[href^=&quot;http&quot;]::after {
		content: &quot;↗&quot;;
		padding-left: 3px;
		display: inline-block;
	}
}
</code></pre>
<h4>Code breakdown</h4>
<dl>
<dt><code>[href^=&quot;http&quot;]</code></dt>
<dd>This means a <code>href</code> attribute inside <code>&lt;a&gt;</code>, starting with the word <code>http</code>, will be styled. Attribute selectors use <strong>square brackets</strong>.</dd>
<dt><code>::after</code></dt>
<dd><code>::after</code>, in this case, lets you add content to the element you're targeting. This content is not added into the HTML document, therefore it's commonly used for visuals or cosmetics.</dd>
<dt><code>padding-left</code></dt>
<dd>This gives a little space between the link and the arrow.</dd>
<dt><code>display: inline-block</code></dt>
<dd><code>inline-block</code> makes it so the arrow won't have an underline.</dd>
</dl>
<h2>Demo #2: Automatically Add &quot;New&quot; Indicator to Your Newest Blog Posts</h2>
<figure><img src="https://nev.nya.je/guides/assets/css-attr-01.png#center" alt="Automatically Add &quot;New&quot; Indicator to Your Newest Blog Posts" loading="lazy" decoding="async"></figure>
<p>Let's say you want to tell visitors that you have a new blog post. Instead of manually adding an image to your newest blog post title, why don't we try using <code>::after</code> like we did in the previous section? For this guide, I'm using this image: <img src="https://nev.nya.je/assets/indicators/new.gif" alt="New"> from <a href="https://foollovers.com/mat/i-new10.html">Foollovers</a>.</p>
<p><em>This section doesn't use attribute selector.</em></p>
<h3>Case #1: Listless structure</h3>
<p>Perhaps you have a section for your latest blog posts whose contents you don't put in a list, like this:</p>
<pre><code class="language-html">&lt;section class=&quot;blog-container&quot;&gt;
	&lt;article class=&quot;blogpost&quot;&gt;
		&lt;h3 class=&quot;blog-title&quot;&gt;Blog Post 2&lt;/h3&gt;
		&lt;p class=&quot;blog-excerpt&quot;&gt;Summary of my blog post.&lt;/p&gt;
	&lt;/article&gt;
	&lt;article class=&quot;blogpost&quot;&gt;
		&lt;h3 class=&quot;blog-title&quot;&gt;Blog Post 1&lt;/h3&gt;
		&lt;p class=&quot;blog-excerpt&quot;&gt;Summary of my blog post.&lt;/p&gt;
	&lt;/article&gt;
&lt;/section&gt;
</code></pre>
<p>For this case, we can utilise the pseudo-class <code>:first-of-type</code>.</p>
<pre><code class="language-css">.blog-post:first-of-type {
	.blog-title::after {
		content: url(../assets/indicators/new.gif);
		padding-left: 0.5rem;
		display: inline-block;
	}
}
</code></pre>
<h4>Code breakdown</h4>
<dl>
<dt><code>.blog-post:first-of-type</code></dt>
<dd><code>:first-of-type</code> here means that it targets the first <code>.blog-post</code> article in a group of <code>.blog-post</code> articles. This is best when you group these <code>.blog-post</code>s inside a larger container, like <code>.blog-container</code>.</dd>
<dt><code>content: url()</code></dt>
<dd>Unlike the arrow we did in the previous section, we can also insert an image as the content by adding the file's relative path.</dd>
</dl>
<h3>Case #2: Listed or Zonelets-style structure</h3>
<p>If you put your blog titles in a list, or if you use <a href="https://zonelets.net/">Zonelets</a> as your blogging engine, you may have something like this:</p>
<pre><code class="language-html">&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;/posts/03&quot;&gt;Blog post 3&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;/posts/02&quot;&gt;Blog post 2&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;/posts/01&quot;&gt;Blog post 1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</code></pre>
<p>Instead of <code>:first-of-type</code>, we're going to use <code>:first-child</code>!</p>
<pre><code class="language-css">ul li:first-child::after {
	content: url(../assets/indicators/new.gif);
	padding-left: 0.5rem;
	display: inline-block;
}
</code></pre>
<p><code>:first-child</code> targets the first child of <code>li</code>, which is an <code>a</code> tag. The <img src="https://nev.nya.je/assets/indicators/new.gif" alt="New"> image will be appended to the topmost link in the list, which happens to be <code>Blog post 3</code>.</p>
<h2>Demo #3: Style a Certain Word Using <code>span</code> and Attribute Selector</h2>
<p>This is a very self-indulgent case where I want to talk about the lore of my websites, like the following paragraph:</p>
<p>&quot;I originally wanted <span class="devoted">Devoted</span> to be my own personal site, but I somehow dug the idea of making a fansite... so once <span class="devoted">Devoted</span> looked like a fansite and followed a bunch of people, I realised I wanted a site of my own. And that was how <span class="nnj-long">Nev.nya.je</span>, also known as <span class="nnj-short">nnj</span>, was born.&quot;</p>
<p>To get something like this: <span class="devoted">Devoted</span>, we can wrap the site name with <code>span</code> and style it this way:</p>
<pre><code class="language-css">span[class*=&quot;devoted&quot;] {
    font-family: Georgia, 'Times New Roman', Times, serif;
    font-weight: bold;
    font-size: 1.25rem;
    color: white;
    filter: drop-shadow();
    font-style: italic;
}
</code></pre>
<p><code>span[class*=&quot;devoted&quot;]</code> means the styling rule will target any <code>span</code>s containing a <code>class</code> named <code>&quot;devoted&quot;</code> in a whitespace-separated list. That means if I were to assign a class like <code>class=&quot;sitename devoted foo bar YOLO&quot;</code>, the style will still be applied because it has <code>&quot;devoted&quot;</code> in the list of <code>class</code>es.</p>
<h2>Demo #4: Adding an 'Update' Indicator on a Navigation Menu</h2>
<p>Take a look at the picture below.</p>
<figure><img src="https://nev.nya.je/guides/assets/css-attr-02.png#center" alt="A chunk of my fansite's navigation menu, with &quot;Favourite cards&quot; having the 'update' indicator next to it." loading="lazy" decoding="async"></figure>
<p>At times, I'd update a certain page on <span class="devoted">Devoted</span> and want to tell my visitors about it. Below is a portion of my navigation bar code:</p>
<pre><code class="language-html">&lt;div class=&quot;sidebar&quot;&gt;
	&lt;a href=&quot;history.html&quot;&gt;&quot;Meeting Yuzuru&quot;&lt;/a&gt;
	&lt;a href=&quot;card.html&quot; class=&quot;update&quot;&gt;Favourite Cards&lt;/a&gt;
	&lt;a href=&quot;#&quot;&gt;Merch Talk&lt;/a&gt;
	&lt;a href=&quot;oshikatsu.html&quot;&gt;Oshikatsu&lt;/a&gt;
	&lt;a href=&quot;#&quot;&gt;Headcanon&lt;/a&gt;
&lt;/div&gt;
</code></pre>
<p>I used to do it by adding the &quot;update&quot; (credits to <a href="https://foollovers.com/mat/i-new06.html">Foollovers</a>) indicator image next to the page name. Using both attribute selector and the pseudo-element <code>::after</code>, I can make things easier by styling it like this:</p>
<pre><code class="language-css">a[class*=&quot;update&quot;]::after {
	content: url(../assets/icon/update.gif);
	padding-left: 5px;
	display: inline-block;
}
</code></pre>
<p>And there you have it: four scenarios in which you can use attribute selector, pseudo-elements, and pseudo-classes! Not only are they useful, they also make things sooo much easier for me. I hope this 'guide' is useful to you! or if not, I hope you had a great time reading.</p>
]]>
      </content:encoded>
      <pubDate>Fri, 04 Sep 2026 00:00:00 GMT</pubDate>
    </item>
    <item>
      <title>Apply Certain CSS Rules to Specific Browsers</title>
      <link>https://nev.nya.je/guides/browser-specific-css/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/browser-specific-css/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>A band-aid solution to make site elements look more consistent in different browsers</description>
      <content:encoded>
        <![CDATA[<p>I had a problem with <code>-webkit-text-stroke</code> rendered differently across browsers. On Firefox, it looks exactly the way I want, but it's rendered 1 pixel thicker on Safari or Chromium browsers which pisses me off sometimes.</p>
<p>So how can we overcome this? By using <code>@-moz-document url-prefix()</code>. This at-rule will apply specificly to Firefox browsers.</p>
<p>This is my <code>h1</code> rule:</p>
<pre><code class="language-css">header &gt; h1 {
	color: transparent;
	-webkit-text-stroke: 1px #ffffff;
	paint-order: stroke fill;
	font-family: 'Dumbass', monospace;
}
</code></pre>
<p>And then I make an adjustment inside <code>@-moz-document url-prefix()</code> and place it at the bottom of my CSS file, along with my other media query rules like this:</p>
<pre><code class="language-css">@-moz-document url-prefix() {
	header &gt; h1 {
    	-webkit-text-stroke: 2px #ffffff;
		paint-order: stroke fill;
	}
}
</code></pre>
<p>This will make the <code>h1</code> rules inside <code>@-moz-document</code> be applied in Firefox and its forks.</p>
<p>Not just for <code>-webkit-text-stroke</code>, this can be applied on various things, like setting different margins or paddings of certain classes and elements. However, extensively using browser-specific at-rules is bad practice, so please use it when there are no other options.</p>
<p>Below is a comparison before and after the code is applied in two different browsers. Top is Vivaldi (Chromium-based), bottom is Zen (a fork of Firefox).</p>
<table>
<thead>
<tr>
<th>Before</th>
<th>After</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="https://nev.nya.je/guides/assets/browser-specific-01.png#center" alt="webkit-text-stroke. normal stroke on Vivaldi (Chromium), and thinner stroke on Zen (Firefox)"></td>
<td><img src="https://nev.nya.je/guides/assets/browser-specific-02.png#center" alt="webkit-text-stroke after using @-moz-document url-prefix() at-rule. Now it looks closely similar across browsers."></td>
</tr>
</tbody>
</table>
<p><em>Tested with Vivaldi 8.0.4033.50 (Chromium 148.0.7778.273), and Zen 1.19.1b (Firefox 148.0).</em></p>
<h2>&quot;Why not make it applied only to Chrome?&quot;</h2>
<p>I tried and it wasn't possible. Chrome (and by extension Safari) use the same vendor prefix, Webkit, which Firefox <em>also</em> supports. To set Firefox apart in this case is nearly impossible, so I opted to target Firefox instead.</p>
<p>This is the code that I used but sadly didn't work:</p>
<pre><code class="language-css">@media screen and (-webkit-min-device-pixel-ratio:0) {
	header &gt; h1 {
        -webkit-text-stroke: 2px #ffffff;
		paint-order: stroke fill;
    }
}
</code></pre>
<p>It targets all browsers supporting Webkit, Firefox included... which is why it didn't solve my problem.</p>
<h2>&quot;Why not use text-shadow hack instead?&quot;</h2>
<p><code>text-shadow</code>, as much as I want to use it, doesn't suit my needs as it won't work with transparent font colour.</p>
]]>
      </content:encoded>
      <pubDate>Wed, 02 Sep 2026 00:00:00 GMT</pubDate>
    </item>
    <item>
      <title>Using @import to Streamline Style Rules</title>
      <link>https://nev.nya.je/guides/@import/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/@import/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>Make CSS more modular with @import at-rule</description>
      <content:encoded>
        <![CDATA[<p>I use custom fonts most of the time and declare them by adding <code>@font-face</code> on my main CSS file, <code>index.css</code>.  My main pages use <code>index.css</code> and I have no problem with it, but what if I use the same font family on my Journal where it has a completely different set of rules in its CSS file?</p>
<pre><code class="language-html">&lt;link rel=&quot;stylesheet&quot; href=&quot;index.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;journal.css&quot;&gt;
</code></pre>
<p>Usually, I will add the above lines to my Journal's <code>head</code> tag so I can use the same font family used in my <code>index.css</code>. If I use this, some rules not explicitly declared in <code>journal.css</code> will use the ones in <code>index.css</code> and that will prompt me to redeclare those missing rules in <code>journal.css</code>. That sounds annoying, to be honest.</p>
<p>A workaround I recently discovered is to use <code>@import</code>. This allows a CSS file to import other rules declared in different CSS files. <strong>All <code>@import</code> rules must be declared at the topmost of your CSS files.</strong></p>
<p>This is how I'd normally declare a custom font inside my <code>journal.css</code>:</p>
<pre><code class="language-css">@font-face {
  font-display: swap; 
  font-family: 'Iosevka Charon';
  font-style: normal;
  font-weight: 400;
  src: url('../assets/fonts/iosevka-charon-v1-latin-regular.woff2') format('woff2');
}
</code></pre>
<p>Instead of doing the above, I made a separate CSS file named <code>fonts.css</code> and moved the <code>@font-face</code> rule from <code>journal.css</code> to <code>fonts.css</code>.</p>
<p>To import <code>fonts.css</code>, simply type <code>@import url(fonts.css);</code> at the top of <code>journal.css</code> and add the <code>font-family</code> name inside wherever rules you want. This also works if the target CSS file is outside the importing directory by typing the dir's relative location, like this: <code>@import url(../styles/fonts.css);</code>.</p>
<p>I'm sure there are more things that can benefit from using <code>@import</code>. So far I've found it useful to gather all my custom font declarations inside a single file.</p>
<p>p.s:<code>@import</code> is widely available across major browsers, but might not work on older browsers.</p>
]]>
      </content:encoded>
      <pubDate>Tue, 01 Sep 2026 00:00:00 GMT</pubDate>
    </item>
    <item>
      <title>The Basics of CSS Nesting</title>
      <link>https://nev.nya.je/guides/css-nesting/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/css-nesting/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>Tired of typing class names every time you want to define a rule? This guide may help you speed things up.</description>
      <content:encoded>
        <![CDATA[<p>Do you ever take a moment to look at your CSS and be like, &quot;this can't be real&quot;?</p>
<pre><code class="language-css">.container {
    background;
    padding;
    margin;
    border;
    width;
}

.container a {
    color;
    background;
    text-decoration;
}

.container a:hover {
    color;
    background;
}

.container a:visited {
    color;
}

.container img {
    width;
    height;
}

.container p {
    color;
    font-weight;
}
</code></pre>
<p>Aren't you tired knowing that you have to do that to OTHER divs you might have, you wish there was another way to do it?! Look no further! I can help you with THIS guide! ദ്ദി・ᴗ・)✧</p>
<h2>CSS Nesting: The Definition</h2>
<p>So what is CSS nesting? It's built-in CSS feature that allows you to put rules inside another rule. Take a look at the snippet above.</p>
<p>The snippet above shows a completely normal set of rules in CSS. But what if I told you that we could simply it?</p>
<p>Instead of <code>.container p {}</code>, we can drag the p into <code>.container {}</code>, like this:</p>
<pre><code class="language-css">.container {
    background;
    padding;
    margin;
    border;
    width;

  	p {
     	color;
     	font-weight;
  	}
}
</code></pre>
<h3>What does that mean?</h3>
<p>When we add <code>p</code> element inside <code>.container {}</code>, our browser will translate that statement as <code>.container p{}</code>! This way, you don't need to keep 'calling' for<code> .container</code> class every time you want to declare rules for specific elements, which can reduce the file size. This also helps keeping rules more organised, and possibly keeping elements away from conflicting with each other.</p>
<p>This way of writing in CSS is still considered new, by the way! Previously, you could only achieve this through CSS preprocessor such as SASS, LESS, or Stylus.</p>
<p>With that in mind, we can also add other things beside <code>p</code>. For this example, let's style our link inside the <code>div</code>! With the same way we did with <code>p</code>, we add a into our <code>.container {}</code> class.</p>
<pre><code class="language-css">.container {
    background: white;
    padding: 1%;
    margin: 1%;
    border: 2px solid blue;
    width: fit-content;

    p { /* Same meaning as .container p {} */
        color: purple;
        font-weight: bold;
    }

    a { /* Same meaning as .container a {} */
        color: green;
    }
}
</code></pre>
<p>Looks neat, doesn't it?</p>
<h3>Inserting a class inside another class</h3>
<p>Did you know that you could also put a class inside another class? For this example, I'd like to add a <code>.box</code> class that gives an orange border around our text. This is how we do it without nesting:</p>
<pre><code class="language-css">.container {}

.container .box{}
</code></pre>
<p>With nesting, simply move the child class into its parent like this:</p>
<pre><code class="language-css">.container {
    .box {
        
    }
}
</code></pre>
<h3>Nesting a pseudo-class using nesting selector (&amp;)</h3>
<p>Perhaps you want to make the background colour of a link change when hovered over, so you want to add <code>:hover</code> rule inside <code>a</code>. With what you've learned so far, you might think it was obviously like this:</p>
<pre><code class="language-css">.container {
    a {
        :hover {
            color;
            background;
        }
    }
}
</code></pre>
<p>And yet, after you add it, the hover effect doesn't work. Why is that? That is because the browser thinks you meant <code>.container a :hover</code>, meaning it will select any (<code>*</code>) hovered descendants of the link (<code>a</code>) element (as opposed to <code>.container a:hover{}</code>, which means it will select <code>.container</code>'s <code>a</code> element when hovered). Even a whitespace can mean an entirely different thing!</p>
<p>So how can we put pseudo-classes inside an element? By using '<code>&amp;</code>', the nesting selector!</p>
<p>When we combine (<code>&amp;</code>) with pseudo-classes, we tell the browser to remove the whitespace between the pseudo-class and the element. So, we should rewrite the code above this way:</p>
<pre><code class="language-css">.container {
    a {
        &amp;:hover {
            color;
            background;
        }
    }
}
</code></pre>
<p>This is what the browser will translate the above to!</p>
<pre><code class="language-css">.container {}

.container a {}

.container a:hover {}
</code></pre>
<p>You can also combine multiple pseudo-classes too! Simply separate them with the comma (also known as selector list).</p>
<pre><code class="language-css">.container {
    a {
        &amp;:hover, &amp;:active, &amp;:focus {
            color;
            background;
        }
    }
}
</code></pre>
<p>If you've played around with pseudo-elements like <code>::before</code> and <code>::after</code>, yes, you can also nest them inside a parent element. Just a quick note that you cannot nest rules inside pseudo-elements.</p>
<pre><code class="language-css">.container {
    a {
        &amp;:hover, &amp;:active, &amp;:focus {}

        &amp;::before {} &lt;----------------- this is valid
    }
}

.container {
    a {
        &amp;:hover, &amp;:active, &amp;:focus {}

        &amp;::before { 
            &amp;::after {} &lt;----------------- this is invalid and will be ignored
        } 
    }
}
</code></pre>
<h4>Further use of <code>&amp;</code> selector</h4>
<h5>Visual aid</h5>
<p>When nesting elements such as <code>a</code>, <code>img</code>, <code>p</code>, and more, you can have the option to use <code>&amp;</code> or not. Either way, the browser will translate them as if you declare rules explicitly. Using <code>&amp;</code> like this <code>&amp; a {}</code> is generally to remind you, in case you forgot, that you nested that element inside a class or another element.</p>
<h5>Compound selector</h5>
<p>In a case that you would like to use two classes in a single element like <code>div class=&quot;classA classB&quot;</code>, you must use <code>&amp;</code> followed by the class name with no space between them, like this:</p>
<pre><code class="language-css">.classA {
    &amp;.classB {}
}
</code></pre>
<p>This is to tell the browser to not add whitespace when translating that nested statement. Otherwise, classB will be translated as <code>.classA .classB {}</code>. Compound selector is different from <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/Descendant_combinator">descendant combinator</a>.</p>
<h5>Reversing context</h5>
<p>If you add <code>&amp;</code> at the end of a nested class name, you'll switch the order of the way the rule is declared.</p>
<pre><code class="language-css">.classA {
    .classB &amp; {}     &lt;------ gets translated as .classB .classA {}
}
</code></pre>
<p>If you're feeling daring, you can use multiple <code>&amp;</code>s. I've personally never used it.</p>
<pre><code class="language-css">.classA {
   .classB &amp; &amp; &amp; {} &lt;------ translated as .classB .classA .classA .classA {}
}
</code></pre>
<h3>Full rewritten code</h3>
<p>Below is the result of the code, rewritten with implementing CSS nesting:</p>
<pre><code class="language-css">.container {
    background: white;
    padding: 1%;
    margin: 1%;
    border: 2px solid blue;
    width: fit-content;

    img {
        width: auto;
        height: auto;
    }

    p {
        color: purple;
    }

    a {
        color: green;

        &amp;:hover, &amp;:active, &amp;:focus {
            color: white;
            background: blue;
        }

        &amp;:visited{
            color: brown;
            background: none;
        }
    }

    .box {
        border: 2px solid orangered;
    }
}
</code></pre>
<h2>&quot;Um... what's the catch?&quot;</h2>
<p>You've seen me enthusiastically talk about CSS nesting. It does sound too good to be true, doesn't it? And then you'll probably be thinking: what's the catch?</p>
<h3>Available only to newer browsers</h3>
<p>Nesting was proposed sometime in 2010s and recently became available on native CSS in 2023. Therefore, CSS nesting is <strong>only available on newer version of major browsers</strong>.</p>
<h3>Specifity issues</h3>
<p>Another problem that comes from using CSS nesting is specifity. To my best knowledge, every rules in CSS has a set of points that will be used by browsers to determine which rule is the most relevant.</p>
<p>Between the sentence &quot;A fast red sports car&quot; and &quot;A red car&quot;, which one is more specific? The first one, because it has values added to the car, such as 'fast' and 'sports car'.</p>
<p>The same thing applies to CSS rules.</p>
<pre><code class="language-css">body {
  p {
     margin: 50px;
     color: green;
  }
}

p {
  margin: 30px;
}

.container {
  p {
    margin: 20px;
  }
}
</code></pre>
<p>All <code>p</code> will have <code>margin: 50px;</code> because <code>body p</code> has more weight than <code>p {}</code>, but all <code>p</code> inside <code>.container</code> will have <code>margin: 20px</code> because <code>.container p</code> overrides the margin. In addition, <code>p</code> inside <code>.container</code> will be green because it inherits the property from <code>body</code>.</p>
<p>Then, consider this:</p>
<pre><code class="language-css">body {
  p {
    margin: 20px;
  }
}

@media only screen and (max-width: 600px) {
   p {
    margin: 0;
   }
}
</code></pre>
<p>Let's say you have different margin for <code>p</code> in screens 600px wide, so you simply made <code>margin: 0</code> in <code>p</code>. Which margin will the phone browser render? <code>margin: 20px</code>, because it holds more weight. The only solution to this will be to nest <code>p</code> inside <code>body</code> within the @media at-rule, or to be more specific, which will introduce more problems down the line. You may find a more proper explanation in <a href="https://blog.frankmtaylor.com/2024/07/18/css-nesting-the-is-pseudo-class-and-a-guide-to-panicking-about-sass/#is-is-problematic">Frank M Taylor's blog post</a>.</p>
<h2>End notes</h2>
<p>Nesting has been drilled into my head since the start of university, back when I was learning Java, and I found out about this after getting tired of making sooo many classes that I only used once. This article is an extended version of my now-deleted blog post ranting about the same thing, and is subject to change.</p>
<h3>Further reading</h3>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Nesting/Using">Using CSS Nesting</a> by MDN. An extensive article on how CSS nesting works.</li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/Nesting_selector">&amp; Nesting Selector</a> by MDN. More on nesting selector.</li>
<li><a href="https://www.alwaystwisted.com/articles/UnSassing-my-CSS-nesting">Un-Sass'ing My CSS: Native CSS Nesting</a>. An article covering what native CSS nesting does, specifity rules, examples, and when to as well as when not to use CSS nesting.</li>
</ul>
]]>
      </content:encoded>
      <pubDate>Sat, 23 May 2026 00:00:00 GMT</pubDate>
    </item>
    <item>
      <title>Reusable Duotone Filter</title>
      <link>https://nev.nya.je/guides/duotone/</link>
      <guid isPermaLink="false">https://nev.nya.je/guides/duotone/</guid>
      <author>
        <name>Nev</name>
        <uri>https://nev.nya.je</uri>
      </author>
      <description>A guide to having a duotone filter for your site with CSS or SVG filters.</description>
      <content:encoded>
        <![CDATA[<p>Duotone has been one of my favourite effects ever since Spotify made them popular in 2016. Now that I know how to use them, I thought I should make a guide on how to do it for anyone who needs it.</p>
<p>There are two ways to achieve this: using pure CSS filter and SVG filter.</p>
<h2>Using pure CSS filter</h2>
<p>Let's start off with <a href="https://cssduotone.com/">CSS duotone generator</a> by <a href="https://x.com/rickymetz">@rickymetz</a>.</p>
<figure><img src="https://nev.nya.je/guides/assets/duotone-tutorial-01.png#center" alt="CSS duotone generator" loading="lazy" decoding="async"></figure>
<p>You'll be greeted with this giant sample picture in the middle and you have options on the right side of it. The right sidebar is your playground! If you don't know what to do in here, here are some options you can play with:</p>
<ul>
<li><strong>Zoom</strong>. Doesn't affect end result.</li>
<li><strong>Spacing</strong>. This will be the padding for the image, which will appear as 'border' around your image later. Depending on the colours you choose, it might appear black, white, or coloured.</li>
<li><strong>Image colour</strong>. This will the topmost colour of the image stack.</li>
<li><strong>Background colour</strong>. This is the colour above your image, but before the image colour.</li>
<li><strong>Image and background blend mode</strong>. Will the colours make the image darker or lighter? That's up for you to decide.</li>
</ul>
<p>I'm a sucker for anything-with-white kind of gradient. To achieve that, pick a <ins>bright colour</ins> for the image colour and <ins>white</ins> as the background colour. Next, set the image blend mode to either <ins>lighten, screen, or color dodge</ins>, and set the background blend mode to <ins>unset</ins>.</p>
<figure><img src="https://nev.nya.je/guides/assets/duotone-tutorial-02.png#center" alt="Duotone image in blue and white" loading="lazy" decoding="async"></figure>
<p>You're free to make your own gradient, of course! Or if you're can't decide, the site has premade settings and a random button.</p>
<p>Once you've found your settings, click the <ins>Generate HTML + CSS</ins> button on the upper part of the sidebar. The web app will give you a pop-up dialogue that shows you blocks of codes. &quot;What in the world is this?!&quot; Don't panic! I'll walk you through it!</p>
<p>Look for codes between the <code>&lt;style&gt;</code> and <code>&lt;/style&gt;</code> tags. Those are the CSS styles needed for the duotone to work. Make a new CSS file in your website's folder. For this tutorial, name it duotone.css. Copy the codes inside <code>&lt;style&gt;</code> and paste them onto your newly made duotone.css.</p>
<p>Your duotone filter is almost ready! Now pick an HTML file where you want to use the filter and link duotone.css to the HTML page like this: <code>&lt;link rel=&quot;stylesheet&quot; href=&quot;duotone.css&quot;&gt;</code> within the <head> tag. Once that's done, put the img tag inside <code>&lt;div class=&quot;img-wrapper&quot;&gt;</code>. The code now should look like this:</p>
<pre><code class="language-html">&lt;div class=&quot;img-wrapper&quot;&gt;
  &lt;img src=&quot;[your image link]&quot;&gt;
&lt;/div&gt;
</code></pre>
<p>If you're not sure what it is, img-wrapper is the duotone effect; in order to make it appear on your image, you <strong>must</strong> put your <code>&lt;img src=&quot;&quot;&gt;</code> inside the <code>&lt;div class=&quot;img-wrapper&quot;&gt;</code>. If you have more than one images, you have to <strong>put every single image inside the container</strong>. If done correctly, your image will appear with the filter applied.</p>
<h3>Spice it up with transitions</h3>
<p>One of the benefits of using CSS filters is the ability to use keyframe animations and transitions. This adds interactivity to the images you put the filters on.</p>
<p>Let me demonstrate an example or two!</p>
<h4>Filter change</h4>
<p>Head back to duotone.css (or the file where you put your duotone effect), and add the following classes (preferably after <code>.img-wrapper::before{}</code>):</p>
<pre><code class="language-css">.img-wrapper:hover img {
    filter: none;
}

.img-wrapper:hover::before {
    background-color: transparent;
    filter: none;
}
</code></pre>
<p><code>.img-wrapper:hover img {}</code> means we're targeting the image inside <code>img-wrapper</code> container when a mouse cursor hovers over it. <code>.img-wrapper:hover::before {}</code> targets the duotone effect when hovered over.</p>
<p><code>filter: none;</code> in both classes mean that when a cursor hovers over the image AND the <code>img-wrapper</code> cpntainer, it will cancel out the contrast given in order to make the duotone work. <code>background-color: transparent;</code> cancels out the dominant colour of the duotone (the colour you set for Image colour in the CSS duotone generator). If you follow through, now your image will have its original colours when hovered.</p>
<h4>Transition time</h4>
<p>Adding time to the filter change above makes the transition go smooth. To use it, simply add <code>transition: [number of seconds];</code> to the following rules:</p>
<ul>
<li><code>.img-wrapper img{}</code></li>
<li><code>.img-wrapper::before{}</code></li>
<li><code>.img-wrapper:hover img{}</code></li>
<li><code>.img-wrapper:hover::before{}</code></li>
</ul>
<p>You can add any number of seconds you want, but I usually pick from 0.25s to 0.5s.</p>
<h4>Zoomed-in effect</h4>
<p>I figured it'd be nice to add some sort of zoomed-in effect, especially if the image's subject is too small. To do this, you can put <code>transform: scale(2);</code> in <code>.img-wrapper:hover img{}</code>. Change the number inside <code>scale()</code> to any number you want.</p>
<p>And there you have it! Your very own duotone filter in CSS!</p>
<p><strong>Just remember:</strong> the duotone is only applied if you wrap your images inside <code>&lt;div class=&quot;img-wrapper&quot;&gt;</code> and think of <code>&lt;div class=&quot;img-wrapper&quot;&gt;</code> as the image itself (quoted this from the duotone generator's pop-up message). Sooo if you want to add more styling (such as height or width), you have to add them inside <code>.img-wrapper {}</code>. This also applies to when you want to add tooltip that appears when you hover over an image: to make the tooltip to work, you need to add <code>title=&quot;&quot;</code> after the class name in <code>&lt;div class=&quot;img-wrapper&quot;&gt;</code> tag of your HTML instead of inside the <code>&lt;img&gt;</code> tag. It should be like this: <code>&lt;div class=&quot;img-wrapper&quot; title=&quot;this is tooltip&quot;&gt;</code>.</p>
<h2>Using SVG filter</h2>
<p>I'm currently using SVG filter to achieve duotone effect for most of my images. Unfortunately my understanding on SVG is little, so this is set up based on what I know. Head to this <a href="https://yoksel.github.io/svg-gradient-map/">SVG Gradient Map Filter generator</a> by <a href="https://twitter.com/yoksel_en">@yoksel_en</a>.</p>
<figure><img src="https://nev.nya.je/guides/assets/duotone-tutorial-04.png#center" alt="SVG gradient map generator by Yoksel" loading="lazy" decoding="async"></figure>
<p>The site has provided you colour palettes to choose from, but you can customise your own. I believe they're all self-explanatory. You can also upload your own image to see the effects in action before putting them in your HTML. There's also options to choose a colour space, either sRGB or linearRGB.</p>
<h3>Where to Put SVG filter</h3>
<p>Just like CSS filters, you can have it either inside an HTML file or on an external/separate file. I'll show you how to do each of them.</p>
<h4>Inside an HTML file</h4>
<p>Before you paste the code from the site, add the following codes before <code>&lt;/body&gt;</code> tag:</p>
<pre><code class="language-html">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; height=&quot;0&quot; width=&quot;0&quot;&gt;

&lt;/svg&gt;
</code></pre>
<p>This tells the HTML that the duotone filter is an SVG filter, and that is because SVG is in XML format. The <code>height=&quot;0&quot;</code> and <code>width=&quot;0&quot;</code> is very important to eliminate the empty space made from the <code>&lt;svg&gt;</code> tag.</p>
<p>Now paste the code from the generator inside the <code>&lt;svg&gt;</code> tag. You should have something like this:</p>
<pre><code class="language-html">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; height=&quot;0&quot; width=&quot;0&quot;&gt;
	/* SVG filter below */
     &lt;filter id=&quot;teal-white&quot; x=&quot;-10%&quot; y=&quot;-10%&quot; width=&quot;120%&quot; height=&quot;120%&quot; 
        filterUnits=&quot;objectBoundingBox&quot; primitiveUnits=&quot;userSpaceOnUse&quot; 
        color-interpolation-filters=&quot;sRGB&quot;&gt;
	&lt;feColorMatrix type=&quot;matrix&quot; values=&quot;0 1 0 0 0
            0 1 0 0 0
            0 1 0 0 0
            0 0 0 1 0&quot; in=&quot;SourceGraphic&quot; result=&quot;colormatrix&quot;/&gt;
	&lt;feComponentTransfer in=&quot;colormatrix&quot; result=&quot;componentTransfer&quot;&gt;
    		&lt;feFuncR type=&quot;table&quot; tableValues=&quot;0.02 1&quot;/&gt;
		&lt;feFuncG type=&quot;table&quot; tableValues=&quot;0 1&quot;/&gt;
		&lt;feFuncB type=&quot;table&quot; tableValues=&quot;1 1&quot;/&gt;
		&lt;feFuncA type=&quot;table&quot; tableValues=&quot;0 1&quot;/&gt;
  	&lt;/feComponentTransfer&gt;
	    &lt;feBlend mode=&quot;normal&quot; in=&quot;componentTransfer&quot; 
                in2=&quot;SourceGraphic&quot; result=&quot;blend&quot;/&gt;
    &lt;/filter&gt;
&lt;/svg&gt;
</code></pre>
<p>Your SVG filter is almost ready! Before we move on to the next step, change the &quot;teal-white&quot; name (or whatever name that comes from the generator) in <code>&lt;filter id=&quot;teal-white&quot;</code> to anything you want. For this tutorial, I'll name my filter &quot;BusinessAsUsual--Blue&quot;.</p>
<p>To apply the filter, go to your CSS file of choice and add <code>filter: url(&quot;#[the SVG filter name]&quot;);</code> in <code>img {}</code> like so:</p>
<pre><code class="language-css">img {
    filter: url(&quot;#BusinessAsUsual--Blue&quot;);
}
</code></pre>
<p>Refresh your page and you should see that the filter has been applied to all your images, provided you've correctly linked your CSS to your HTML.</p>
<p>You can also use the filter with inline CSS, like this:</p>
<pre><code class="language-html">&lt;img src=&quot;[image link]&quot; alt=&quot;[img alt text]&quot; style=&quot;filter: url(#[filter name]);&quot;&gt;
</code></pre>
<h4>Outside the HTML file (external SVG) <img src="https://nev.nya.je/assets/indicators/new.gif" alt="New"></h4>
<p>Make a new SVG file and put it somewhere in your website directory. It can be in same directory level as your index file, inside a sub directory, or in a sub directory within another sub directory.</p>
<p>When you click on the SVG file, your code editor might get an error in displaying the file. Open the file using the built-in text editor and paste the XML codes the same way you'd do inside an HTML file.</p>
<p>Inside the CSS file, add the file name before the filter name. This is how you do it if the SVG file is within the same directory as your CSS file:</p>
<pre><code class="language-css">img {
    filter: url(&quot;filter.svg#BusinessAsUsual--Blue&quot;);
}
</code></pre>
<p>If the SVG is outside your CSS file directory, put a relative path to your SVG file like so:</p>
<pre><code class="language-css">img {
    filter: url('../assets/filter.svg#BusinessAsUsual--Blue');
}
</code></pre>
<p>⚠️ <strong>Warning</strong>: A known bug causes external SVG filters to not appear in <strong>Chromium-based browsers on mobile</strong>.</p>
<h3>Multiple SVG filters</h3>
<p>You can also have more than one duotone filters. Simply get the filter code from the generator and paste it below the first filter, as shown below:</p>
<pre><code class="language-html">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; height=&quot;0&quot; width=&quot;0&quot;&gt;
    &lt;filter id=&quot;BusinessAsUsual--Blue&quot;
        /* content */
    &lt;/filter&gt;
    &lt;filter id=&quot;BusinessAsUsual--Grey&quot;
        /* content */
    &lt;/filter&gt;
    &lt;filter id=&quot;YourSVGFilterName&quot;
        /* content */
    &lt;/filter&gt;
&lt;/svg&gt;
</code></pre>
<p>To apply more filters, add <code>filter: url(&quot;&quot;);</code> inside any classes you want, and put the new filter name inside the <code>url(&quot;&quot;)</code>. Just don't forget the <code>#</code> and the <code>&quot;&quot;</code> inside the brackets (only applies if you use external CSS).</p>
<h3>&quot;Why does my SVG filter make things look like a ghost?&quot;</h3>
<p>It's likely that your filter looks like that because of the grayscale targeting a certain channel.</p>
<figure><img src="https://nev.nya.je/guides/assets/duotone-tutorial-05.png#center" alt="Selection of grayscale channels" loading="lazy" decoding="async"></figure>
<p>Above the colour selections thingy, there's a Grayscale by channel option. The site picks red by default. I recommend you experiment on these, since each one gives a different result! After you pick your desired channel, simply replace the old filter codes inside <code>&lt;svg&gt;</code> and rename your <code>filter id=&quot;&quot;</code> back to your filter name.</p>
<h2>CSS filter vs SVG Filter: The Difference</h2>
<p>So now you learn there are to ways to get duotone filters working on your site. What are the pros and cons to each of them?</p>
<h3>CSS filter</h3>
<table>
<thead>
<tr>
<th>The good</th>
<th>The bad</th>
</tr>
</thead>
<tbody>
<tr>
<td>Easier to customise.</td>
<td><code>img</code> will act as a <code>div</code></td>
</tr>
<tr>
<td>Possibility to add transitions and other effects.</td>
<td></td>
</tr>
</tbody>
</table>
<h3>SVG filter</h3>
<table>
<thead>
<tr>
<th>The good</th>
<th>The bad</th>
</tr>
</thead>
<tbody>
<tr>
<td>Works without a wrapper container.</td>
<td>Harder to animate or give transitions to.</td>
</tr>
<tr>
<td>Can be applied to any other elements, such as <code>div</code>.</td>
<td></td>
</tr>
</tbody>
</table>
<p>Using the CSS filter is best when used for a certain section of your page, like a grid of favourite characters or OCs. If you need a duotone filter and don't really care about giving additional animations/effects, SVG is your best bet.</p>
<p>Don't let my opinions prevent you from choosing whichever you want, though. Go pick one and have fun!</p>
]]>
      </content:encoded>
      <pubDate>Tue, 12 May 2026 00:00:00 GMT</pubDate>
    </item>
  </channel>
</rss>