Gradient text for your website in 5 methods

In this article, I will show you a couple of ways to get gradient text using CSS (and some without CSS). You may already be familiar with one of the methods.

HTML for method – 1, 2 and 3

<h1>Sub to Axorax on YT!</h1>

Meth…


This content originally appeared on DEV Community and was authored by Axorax

In this article, I will show you a couple of ways to get gradient text using CSS (and some without CSS). You may already be familiar with one of the methods.

HTML for method - 1, 2 and 3

<h1>Sub to Axorax on YT!</h1>

Method - 1 (CSS)

h1 {
  background: -webkit-linear-gradient(#e28bfc, #8bb8fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

Method - 2 (CSS)

h1 {
  background: linear-gradient(#e28bfc, #8bb8fc);
  background-clip: text;
  color: transparent;
}

Method - 3 (CSS clip-path)

h1 {
  position: relative;
  display: inline-block;
}

h1::before {
  content: "Sub to Axorax on YT!";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(#e28bfc, #8bb8fc);
  -webkit-background-clip: text;
  color: transparent;
  clip-path: text;
}

Method - 4 (SVG)

<svg width="100%" height="100%">
  <defs>
    <linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
      <stop offset="0%" style="stop-color:#e28bfc;stop-opacity:1" />
      <stop offset="100%" style="stop-color:#8bb8fc;stop-opacity:1" />
    </linearGradient>
  </defs>
  <text x="10" y="50" font-size="72" fill="url(#gradient)">Gradient Text</text>
</svg>

Method - 5 (HTML canvas)

<canvas id="canvas" width="800" height="200"></canvas>

<script>
  const canvas = document.getElementById('canvas');
  const ctx = canvas.getContext('2d');
  ctx.font = '3rem sans-serif';
  const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
  gradient.addColorStop(0, '#e28bfc');
  gradient.addColorStop(1, '#8bb8fc');
  ctx.fillStyle = gradient;
  ctx.fillText('Sub to Axorax on YT!', 10, 100);
</script>

Hope you found something useful!


This content originally appeared on DEV Community and was authored by Axorax


Print Share Comment Cite Upload Translate Updates
APA

Axorax | Sciencx (2024-07-25T17:04:24+00:00) Gradient text for your website in 5 methods. Retrieved from https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/

MLA
" » Gradient text for your website in 5 methods." Axorax | Sciencx - Thursday July 25, 2024, https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/
HARVARD
Axorax | Sciencx Thursday July 25, 2024 » Gradient text for your website in 5 methods., viewed ,<https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/>
VANCOUVER
Axorax | Sciencx - » Gradient text for your website in 5 methods. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/
CHICAGO
" » Gradient text for your website in 5 methods." Axorax | Sciencx - Accessed . https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/
IEEE
" » Gradient text for your website in 5 methods." Axorax | Sciencx [Online]. Available: https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/. [Accessed: ]
rf:citation
» Gradient text for your website in 5 methods | Axorax | Sciencx | https://www.scien.cx/2024/07/25/gradient-text-for-your-website-in-5-methods/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.