CSS Colors
selector {
color: colorValue;
background-color: colorValue;
}
Named Colors
CSS plain English color names का एक set समझती है, जैसे red, blue, और white, जिन्हें आप बिना किसी special formatting के सीधे एक value की तरह इस्तेमाल कर सकते हैं।
- Named colors quick prototypes के लिए बहुत अच्छे हैं, लेकिन जब आपको exact brand color चाहिए हो तो hex या rgb पर switch करें।
- Accepted values:
- named color — red, teal, tomato जैसे keywords
- #rrggbb — hex code, जैसे #ff6600
- rgb(r, g, b) — 0 से 255 तक channels
- hsl(h, s%, l%) — hue, saturation, lightness
- rgba() / hsla() — एक alpha (opacity) channel जोड़ता है
- transparent — पूरी तरह transparent
- currentcolor — element की text color इस्तेमाल करता है
उदाहरण: Named Colors
<style>
p {
color: blue;
background-color: white;
}
</style>
<p>Named colors example</p>
Hex Colors
एक hex color एक hash के बाद छह characters के रूप में लिखा जाता है जो red, green, और blue को pairs में represent करते हैं, जैसे #1a73e8। असली projects में एक exact color express करने का यह सबसे common तरीका है।
- Design tools लगभग हमेशा colors को hex codes के रूप में export करते हैं, इसलिए इन्हें पढ़ना सीखना किसी design को CSS में translate करना कहीं तेज़ बना देता है।
- Accepted values:
- #rrggbb — छह hex digits, जैसे #ff0000
- #rgb — shorthand, जैसे #f00
- #rrggbbaa — alpha channel के साथ
- #rgba — alpha के साथ short form
- Digits 0-9 और a-f होते हैं, case sensitive नहीं
उदाहरण: Hex Colors
<style>
p {
color: #1a73e8;
}
</style>
<p>Hex color example</p>
RGB और RGBA
rgb() function red, green, और blue के लिए 0 से 255 के बीच तीन numbers से एक color बनाता है। एक चौथी value (rgba) जोड़ने से opacity control होती है, 0 (invisible) से 1 (पूरी तरह solid) तक।
- जब भी आपको ऐसा color चाहिए जो थोड़ा see-through हो, जैसे किसी image के ऊपर एक subtle overlay, तो rgba() इस्तेमाल करें।
- Accepted values:
- rgb(r, g, b) — हर channel 0 से 255
- rgb(r g b) — modern space-separated syntax
- rgb(r g b / a) — slash के बाद alpha जोड़ता है
- rgb(0% 50% 100%) — channels percentages के रूप में
- rgba(r, g, b, a) — 0 से 1 तक alpha वाला legacy alias
उदाहरण: RGB and RGBA
<style>
p {
color: rgb(26, 115, 232);
background-color: rgba(0, 0, 0, 0.5);
}
</style>
<p>RGB and RGBA example</p>
HSL और HSLA
hsl() function किसी color को hue (color wheel पर एक position, 0 से 360), saturation (color कितना vivid है), और lightness (वह कितना हल्का या गहरा है) से describe करता है, जो कई लोगों को rgb से ज़्यादा intuitive लगता है।
- HSL matching color variations बनाना आसान बना देता है, बस lightness value को ऊपर या नीचे adjust करें ताकि उसी hue के हल्के या गहरे shades मिल जाएँ।
- Accepted values:
- hsl(h, s%, l%) — hue, saturation, lightness
- hue — 0 से 360 तक का angle (0 red, 120 green, 240 blue)
- saturation — 0% gray है, 100% पूरी तरह vivid है
- lightness — 0% black है, 50% pure color है, 100% white है
- hsl(h s% l% / a) — alpha वाला modern syntax
उदाहरण: HSL and HSLA
<style>
p {
color: hsl(210, 82%, 51%);
}
</style>
<p>HSL color example</p>
Accessible Color Contrast चुनना
हर color combination पढ़ने में आसान नहीं होता। Accessible design का मतलब है text और उसके background के बीच इतना contrast चुनना कि कम vision या color blindness वाले visitors भी उसे सहजता से पढ़ सकें।
उदाहरण: Choosing Accessible Color Contrast
<style>
.good-contrast {
color: #111111;
background-color: #ffffff;
}
.poor-contrast {
color: #eeeeee;
background-color: #ffffff;
}
</style>
<p class="good-contrast">Easy to read</p>
<p class="poor-contrast">Hard to read</p>
- किसी बहुत specific brand color के लिए exact hex या rgb value के बजाय एक color name इस्तेमाल करना।
- यह भूल जाना कि rgba() और hsla() को opacity के लिए 0 और 1 के बीच एक चौथी value चाहिए होती है।
- text और background के बीच बहुत कम contrast वाले colors चुनना, जो readability को नुकसान पहुँचाता है।
- CSS colors को named colors, hex codes, rgb()/rgba(), या hsl()/hsla() के रूप में लिखा जा सकता है।
- असली projects में exact brand colors express करने का सबसे common तरीका hex codes हैं।
- rgba और hsla में a एक alpha channel जोड़ता है जो transparency control करता है।
यहाँ बताए गए सभी standard CSS color formats हर modern browser में supported हैं।
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- CSS Colors
- CSS RGB Colors
- CSS HEX Colors
- CSS HSL Colors
- CSS Color Keywords
- CSS Backgrounds
- CSS Background Color
- CSS Background Image
- CSS Background Repeat
- CSS Background Attachment
- CSS Background Shorthand
- CSS Multiple Backgrounds
- CSS Background Size
- CSS Background Origin
- CSS Background Clip
- CSS Borders
- CSS Border Style
- CSS Border Width
- CSS Border Color
- CSS Border Sides
- CSS Border Shorthand