Skip to content

Less - Color Defination Functions

LESS provides a powerful set of built-in functions for defining colors. These functions allow you to create colors using various color models like RGB, HSL, and HSV, providing flexibility in how you specify colors in your stylesheets. These are foundational for dynamic theming and consistent color palettes.

Sr.No.Function & DescriptionExample & Output
1rgb(red, green, blue)
Creates a color from Red, Green, and Blue channel values.

Parameters:
  • red: An integer between 0-255 or a percentage 0-100%.
  • green: An integer between 0-255 or a percentage 0-100%.
  • blue: An integer between 0-255 or a percentage 0-100%.
color: rgb(220, 20, 60);

Output: #dc143c (Crimson)

2rgba(red, green, blue, alpha)
Creates a color from Red, Green, Blue, and Alpha (transparency) channel values.

Parameters:
  • red, green, blue: Same as rgb().
  • alpha: A number between 0 (transparent) and 1 (opaque), or a percentage 0-100%.
color: rgba(220, 20, 60, 0.5);

Output: rgba(220, 20, 60, 0.5)

3argb(color)
Creates an ARGB hexadecimal representation of a color (e.g., #AARRGGBB).

Parameter:
  • color: A LESS color object.

Note: While available, direct usage of ARGB hex is less common in modern CSS than RGBA or 8-digit hex (#RRGGBBAA).
background: argb(rgba(176, 23, 31, 0.5));

Output: #80b0171f

4hsl(hue, saturation, lightness)
Creates a color from Hue, Saturation, and Lightness values.

Parameters:
  • hue: An integer 0-360 representing degrees on the color wheel.
  • saturation: A percentage 0-100% or a number 0-1.
  • lightness: A percentage 0-100% or a number 0-1.
color: hsl(120, 100%, 50%);

Output: #00ff00 (Lime Green)

5hsla(hue, saturation, lightness, alpha)
Creates a color from Hue, Saturation, Lightness, and Alpha values.

Parameters:
  • hue, saturation, lightness: Same as hsl().
  • alpha: A number between 0-1 or a percentage 0-100%.
color: hsla(0, 100%, 50%, 0.5);

Output: rgba(255, 0, 0, 0.5) (Semi-transparent Red)

6hsv(hue, saturation, value)
Creates a color from Hue, Saturation, and Value (Brightness) values.

Parameters:
  • hue: An integer 0-360.
  • saturation: A percentage 0-100% or a number 0-1.
  • value: A percentage 0-100% or a number 0-1.
color: hsv(80, 90%, 70%);

Output: #7db312

7hsva(hue, saturation, value, alpha)
Creates a color from Hue, Saturation, Value, and Alpha values.

Parameters:
  • hue, saturation, value: Same as hsv().
  • alpha: A number between 0-1 or a percentage 0-100%.
color: hsva(80, 90%, 70%, 0.6);

Output: rgba(125, 179, 18, 0.6)

These definition functions are often used in conjunction with LESS Color Operation Functions (e.g., lighten(), darken(), saturate()) to create dynamic and harmonious color schemes.