<?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: Henry Clay</title>
    <description>The latest articles on DEV Community by Henry Clay (@clayhdev).</description>
    <link>https://dev.to/clayhdev</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%2F2929322%2F7d058df8-659e-4be0-a832-4f809c99f763.png</url>
      <title>DEV Community: Henry Clay</title>
      <link>https://dev.to/clayhdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/clayhdev"/>
    <language>en</language>
    <item>
      <title>Transparent Outlines for HTML Elements Using Vanilla CSS</title>
      <dc:creator>Henry Clay</dc:creator>
      <pubDate>Mon, 10 Mar 2025 20:24:21 +0000</pubDate>
      <link>https://dev.to/clayhdev/transparent-outlines-for-html-elements-using-vanilla-css-i87</link>
      <guid>https://dev.to/clayhdev/transparent-outlines-for-html-elements-using-vanilla-css-i87</guid>
      <description>&lt;p&gt;Recently I decided to update my personal website. I ran into a problem I wanted to solve that I could not find an easy off-the-shelf solution for. So, I decided to write up my discovery of a solution, in hopes it helps someone down the line! &lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I have been inspired recently by ice dyed tie dye shirts and 2000s era JRPG UIs, and I wanted to try to hack together something similar to present myself. &lt;/p&gt;

&lt;p&gt;The first thing I did was add a gradient to my text. There are numerous wonderful guides for doing this via&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  background-clip: text;
  color: transparent;
  backgroundImage: `radial-gradient`;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and I was happy with the results I got with a quick implementation. &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%2Fbgjjz104mteq7kyaxc4c.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%2Fbgjjz104mteq7kyaxc4c.png" alt="Image description" width="754" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding movement
&lt;/h2&gt;

&lt;p&gt;The next step was for the gradient to move with the user's mouse to give it an underwater glimmer (and make my simple text display pages interactive!)&lt;/p&gt;

&lt;p&gt;For this, I found a wonderful tutorial from Axell Martinez, posted on Medium in 2023: [&lt;a href="https://axellmartinezdev.medium.com/how-to-move-a-gradient-with-mouse-react-js-88281e9c3f9f" rel="noopener noreferrer"&gt;https://axellmartinezdev.medium.com/how-to-move-a-gradient-with-mouse-react-js-88281e9c3f9f&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;This worked great! Axell's approach of creating a custom div that just handled the gradient allowed me to factor out the logic into it's own component sitting at a high level in my app's layout, so that the gradient wouldn't need to reload with every component/page change. &lt;/p&gt;

&lt;p&gt;Thank you Axell! &lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Borders
&lt;/h2&gt;

&lt;p&gt;I had one final goal for this re-design, which was to create borders for the text containers that were outlined with the same gradient as the text. &lt;/p&gt;

&lt;p&gt;This proved tricky at first. Gradient borders, per se, were not a particularly difficult task, but all the ready-made implementations were either adding a specific background-clip effect per-div, which would get in the way of the way I was already using &lt;code&gt;background-clip: text;&lt;/code&gt;, or adding a gradient to the div itself. &lt;/p&gt;

&lt;p&gt;In order to get the text and the borders displaying the same gradient (the moving one I implemented earlier), I needed to find another way to make the borders transparent. Simply adding borders and making them transparent did not work, they vanished (or rather transparently displayed the non-transparent mask I was clipping in order to get the effect working). &lt;/p&gt;

&lt;p&gt;I settled on making them a sort of light misty grey, thinking I could  fake the effect by fading the text color to match, when I had a breakthrough moment. As I lowered the transparency in my css block&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%2Fm7o1zm07e4zkkpmo26k9.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%2Fm7o1zm07e4zkkpmo26k9.png" alt="Image description" width="800" height="349"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-color: transparent;
  outline-style: solid;
  outline-color: rgba(100, 100, 100, ~~0.9~~ 0.5);
  outline-width: 3px;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I noticed some color appearing in the border, and increasing as I lowered the opacity of outline-color. It was a little shaded, however. &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%2Fzs4x3srtxd3tqy5ocd5u.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%2Fzs4x3srtxd3tqy5ocd5u.png" alt="Image description" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But with &lt;code&gt;outline-color rgba(255, 255, 255, 0.1);&lt;/code&gt; the masking was barely noticeable, and my gradient was visible through it! NB: setting the opacity to 0.0 is the same `outline-color: transparent, which results in the gradient outline disappearing. &lt;/p&gt;

</description>
      <category>css</category>
      <category>frontend</category>
      <category>vanilla</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
