You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Used to perform mathematical operations on CSS values
width: calc(100% - 20px);
attr()
attr(attributeName)
Returns the value of an element's attribute
content: attr(data-title);
url()
url(urlString)
Specifies a URL as the value for a CSS property
background-image: url('bg.png');
rgba()
rgba(red, green, blue, alpha)
Specifies a color value with opacity
color: rgba(255, 0, 0, 0.5);
hsl()
hsl(hue, saturation, lightness)
Specifies a color value in the HSL
color space color: hsl(0, 100%, 50%);
var()
var(--custom-variable)
Uses a custom CSS variable (CSS custom property)
background-color: var(--bg-color);
Rules of Specificity
Elements and Pseudo-Elements Selectors
These selectors target specific HTML elements, such as p or h1, or a pseudo-element of an element, such as ::before or ::after. The specificity value of an element selector is 0 0 0 1.
Class, Attribute, and Pseudo-Class Selectors
These selectors target elements based on their class, attribute, or a certain state or behavior. For example, .highlight, [href="https://www.example.com"], or :hover. The specificity value of a class, attribute, or pseudo-class selector is 0 0 1 0.
ID Selectors
These selectors target elements based on their unique ID attribute. For example, #header. The specificity value of an ID selector is 0 1 0 0.
Inline Styles
These selectors target elements that have an inline style attribute. The specificity value of an inline style is 1 0 0 0.
Layers
This selector is not part of the CSS specification, but it is sometimes used to refer to the stacking order of elements in CSS. The exact specificity value of a layer selector is not defined.
!important
This selector allows you to increase the priority of a particular CSS rule, making it more important than other rules with equal or lower specificity values. The specificity value of !important is always the highest and takes precedence over all other rules, regardless of specificity value.
In terms of specificity, the most specific selector wins, meaning that if two selectors are targeting the same element, the selector with the higher specificity will take precedence. If two selectors have the same specificity value, the later rule in the stylesheet will take precedence.