- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS Function - rgb()
The rgb() function in CSS is used to define a color value using the RGB (Red, Green, Blue) color model. It allows you to specify a color by specifying the intensity of each of these three primary colors.
To add the color transparency, an optional <alpha-value> can be passed to the rgb() function.
The legacy function rgba() is an alias to function rgb() and they both accept the same parameters and behave in the same manner.
Possible values
The functional notation for rgb() function is rgb(R G B[ / A]).
R, G, B: Can contain any of the format(s), that represents the red, green, and green channels, respectively :
<number>: Any number between 0 and 255.
<percentage>: Any value between 0% and 100%.
keyword none
A: Represents the transparency of the color. It is an optional value.
<alpha-value>: any number between 0 and 1, where 1 corresponds to full opacity and 0 corresponds to full transparency.
keyword none
The values of the red, green and blue components are rounded in serialization, as the functional notation serializes it as sRGB.
Syntax
rgb(255 255 255) | rgb(255, 255, 255) | rgb(255 255 255 /0.5)
CSS rgb() - Number Value
Following is an example showing the usage of rgb() function where all the three values are passed with and without the alpha value (number values):
<html> <head> <style> div { width: 100px; height: 100px; border: 2px solid black; margin-bottom: 10px; } .color-rgb-red{ background-color: rgb(255 0 0); } .color-rgb-green{ background-color: rgb(0 255 0); } .color-rgb-blue{ background-color: rgb(0 0 255); } .color-rgb-alpha{ background-color: rgba(255 0 0 /0.5); } </style> </head> <body> <div class="color-rgb-red">rgb(255 0 0)</div> <div class="color-rgb-green">rgb(0 255 0)</div> <div class="color-rgb-blue">rgb(0 0 255)</div> <div class="color-rgb-alpha">rgba(255 0 0 /0.5)</div> </body> </html>
CSS rgb() - Percentage Value
Following is an example showing the usage of rgb() function where all the three values are passed with and without the alpha value (percentage values):
<html> <head> <style> div { width: 100px; height: 100px; border: 2px solid black; margin-bottom: 10px; } .color-rgb-red { background-color: rgb(70% 30% 10%); } .color-rgb-comma { background-color: rgb(0%, 55%, 20%); } .color-rgb-blue { background-color: rgb(10% 10% 85%); } .color-rgb-alpha-number { background-color: rgba(0% 40% 50% /0.5); } .color-rgb-alpha-percent { background-color: rgba(70% 0% 50% /12%); } </style> </head> <body> <div class="color-rgb-red">rgb(70% 30% 10%)</div> <div class="color-rgb-comma">rgb(comma-separated)</div> <div class="color-rgb-blue">rgb(10% 10% 85%)</div> <div class="color-rgb-alpha-number">rgba(0% 40% 50% /0.5)</div> <div class="color-rgb-alpha-percent">rgba(70% 40% 50% /12%)</div> </body> </html>
To Continue Learning Please Login
Login with Google