← Back to CSS Course | Chapter 2: Colors & Backgrounds | Lesson 4 of 21

CSS HSL Colors

HSL किसी color को उस तरीके से describe करता है जैसे कोई इंसान naturally उसके बारे में सोचता है -- blue जैसा एक base hue चुनें, फिर तय करें कि वह कितना vivid और कितना bright होना चाहिए -- raw light channels mix करने के बजाय।
Syntax
css
selector {
  color: hsl(hue, saturation%, lightness%);
  color: hsla(hue, saturation%, lightness%, alpha);
}

hsl() Function

hsl(hue, saturation, lightness) एक hue लेता है color wheel पर एक degree के रूप में (0-360, जहाँ 0 red है, 120 green है, 240 blue है), फिर saturation और lightness percentages के रूप में। hsl(0, 100%, 50%) pure red है, और सिर्फ hue value को rotate करना saturation या lightness को छुए बिना smoothly color wheel के चारों ओर move करता है।

Note:
  • Accepted values:
  • hsl(hue, saturation, lightness) — पूरा syntax
  • hue — 0 से 360 तक का angle; units deg, rad, grad, turn (default deg)
  • saturation — 0% (gray) से 100% (vivid)
  • lightness — 0% (black) से 100% (white), 50% normal है
  • hsla() या hsl(h s l / a) — alpha जोड़ता है

उदाहरण: The hsl() Function

css
<style>
.red { background: hsl(0, 100%, 50%); }
.green { background: hsl(120, 100%, 50%); }
.blue { background: hsl(240, 100%, 50%); }
</style>
<div class="red">hue 0</div>
<div class="green">hue 120</div>
<div class="blue">hue 240</div>

Saturation को समझना

Saturation control करता है कि कोई color कितना vivid या muted है: 100% उस hue का पूरी तरह saturated, vibrant version है, जबकि 0% hue value चाहे जो भी हो एक ऐसा gray है जिसमें बिल्कुल color नहीं है। किसी brand color का muted, pastel, या desaturated variant बनाने का सबसे आसान तरीका saturation को कम करना है।

Note:
  • Accepted values:
  • 0% — पूरी तरह gray
  • 50% — muted, softened color
  • 100% — पूरी तरह vivid color

उदाहरण: Understanding Saturation

css
<style>
.vivid { background: hsl(210, 100%, 50%); }
.muted { background: hsl(210, 20%, 50%); }
.gray { background: hsl(210, 0%, 50%); }
</style>
<div class="vivid">100% saturation</div>
<div class="muted">20% saturation</div>
<div class="gray">0% saturation — gray</div>

Lightness को समझना

Lightness control करता है कि कोई color black या white के कितना करीब है: 0% हमेशा black होता है, 100% हमेशा white होता है, और 50% pure, undiluted hue है।

क्योंकि lightness इस तरह काम करती है, एक hue से पूरा tint-and-shade palette बनाना उतना ही आसान है जितना hue और saturation को constant रखते हुए lightness value को sweep करना।

Note:
  • Accepted values:
  • 0% — हमेशा black
  • 50% — pure, unmixed color
  • 100% — हमेशा white

उदाहरण: Understanding Lightness

css
<style>
.black { background: hsl(210, 100%, 0%); }
.pure { background: hsl(210, 100%, 50%); }
.white { background: hsl(210, 100%, 100%); }
</style>
<div class="black">0% lightness</div>
<div class="pure">50% lightness</div>
<div class="white">100% lightness</div>

HSL Adjust करना क्यों आसान है

क्योंकि hue, saturation, और lightness independent हैं, HSL उन common design tweaks को trivial बना देता है जो RGB या hex में awkward होते हैं -- किसी color को darken करने का मतलब है lightness को एक fixed amount से कम करना, और desaturate करने का मतलब है saturation कम करना, बिना हाथ से तीन अलग-अलग channel values recompute किए।

उदाहरण: Why HSL Is Easier to Adjust

css
<style>
.base { background: hsl(210, 80%, 50%); }
.darker { background: hsl(210, 80%, 30%); }
.desaturated { background: hsl(210, 30%, 50%); }
</style>
<div class="base">Base color</div>
<div class="darker">Darker: lightness lowered</div>
<div class="desaturated">Desaturated: saturation lowered</div>

hsla() से Transparency जोड़ना

hsla(hue, saturation, lightness, alpha) rgba() जैसा ही 0-से-1 alpha channel जोड़ता है, जिससे किसी color को semi-transparent बनाया जा सकता है जबकि HSL के intuitive hue/saturation/lightness controls बने रहते हैं। जब आपको एक ही declaration में color tweaking की आसानी और transparency दोनों चाहिए हों तो यह natural choice है।

Note:
  • Accepted values:
  • hsla(h, s%, l%, a) — 0 से 1 तक alpha
  • hsl(h s% l% / a) — modern syntax; alpha number या percentage हो सकता है
  • alpha 0 — पूरी तरह transparent
  • alpha 1 — पूरी तरह opaque

उदाहरण: Adding Transparency with hsla()

css
<style>
.overlay {
  background: hsla(210, 100%, 50%, 0.4);
}
</style>
<div class="overlay">Semi-transparent HSL color</div>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. hue को percent sign के साथ लिखना, जैसे hsl(50%, 100%, 50%), जबकि hue degrees में एक number है।
  2. saturation या lightness पर % छोड़ देना, जैसे hsl(200, 50, 50), जो classic syntax में invalid है।
  3. lightness को 0% या 100% set करना और hue व saturation चाहे जो भी हो pure black या white मिलना।
ब्राउज़र सपोर्ट

हर modern browser में supported: Chrome, Firefox, Safari, Edge और Opera।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.