CSS Research BIS 22 SS 009
CSS Research BIS 22 SS 009
NAME:
Prince Jimu BIS/22/SS/009
COURSE
Web Technologies (WEB-301)
DUE DATE
20 Feb 2025
CSS SPECIFICITY
Specificity is a feature of CSS that allows the browser to use an algorithm to determine the
styling value to be applied to an element if the element has been given conflicting property
values using different selectors. For example, if an element has been targeted in an external CSS
file using its class name (.card) and its id (#info-card), and the same property is given different
values in the selections, the algorithm determines which style to apply to the element.
There is a hierarchy of selectors that is used by the algorithm to determine which style to render.
According to Mozzilla (2025), the algorithm uses weight to determine the style block of higher
precedence. It calculates this weight by counting the number of “selectors of each weight
category”. The Order is as follows:
Selector Specificity value
ID e.g. #main-menu 1,0,0
Class name e.g. .menu 0,1,0
Tag Selector e.g. p, h1 0,0,1
No value Selectors e.g. * (all) N/A (Does not affect Specificity)
If multiple selectors are used, for example #wrapper .upper , the browser adds up the specificity
values of the selectors present. In this case, the browser will add the specificity value of one ID
(1,0,0) and one class (0,1,0) to get (1,1,0). If there is another styling block with a selector group
with a higher specificity value, that block will be prioritized. If not, then the styling in this given
block will take effect.
Apart from these precedence values, inline CSS has the highest Specificity and therefore will
always be rendered regardless of the values of the selectors in the internal or external CSS.
Examples Showing Specificity:
1. Inline Precedence:
Inline CSS Tag Selector Output
<h1 style="color: blue;"> h1{ color: red;
Testing Header }
</h1>
2. ID precedence:
ID Selector Class Selector Output
#top-title{ color: red; .main-title{color:
} grey;}
CSS Color Values
As described by MDN (2024), color codes and values are used to define color to the computer.
The values of different color codes represent amounts of variables like brightness, hue, saturation
or amounts of primary colors (Red, Blue, Green) mixed to create the color rendered to the
screen.
CSS also has in built color names such as “blue” and “orangered”.
Color Code Meaning Values Example
RGB (red, green, blue) From 0-255 representing (0,255,0) – green
each color or percentages.
RGBA (red, green, blue, Similar to rgb with alpha (0,0,255,255)-Blue
alpha) value representing opacity.
HEX #RRGGBB Hexadecimal values Ranging #0000FF - blue
from 00 to FF with two digits
representing one color
HSL (Hue, Saturation, Hue – defines the color, (147, 50%, 47%)-
Lightness) ranges from 0-360 shade of green
Saturation-is a percentage of
color saturation.
Lightness-the brightness of
the color
HSLA (Hue, Saturation, Similar to HSL with an alpha (147, 50%, 47%)-
Lightness, value green
Alpha)
https://developer.mozilla.org/enUS/docs/Web/CSS/CSS_cascade/Specificity
https://www.simplilearn.com/tutorials/css-tutorial/css-colors#css_colors
Gayathri. (2023). Which is the Best Image Format for Your Website?.
https://imagekit.io/blog/best-image-format-for-web/