Search code examples
csscss-selectorscss-specificity

CSS type selector overrides attribute selector?


Generally speaking, an attribute selector has higher specificity than a type selector, but in the image below, the type selector wins (margin is set to 0)?

Is it because user agent stylesheet (browser default style) always gets overridden by custom CSS regardless of CSS specificity?

enter image description here


Solution

  • Is it because user agent stylesheet (browser default style) always gets overridden by custom CSS regardless of CSS specificity?

    Yes. The technical name for "custom CSS" is author-level CSS as detailed in this section of the spec. Specificity is only relevant when you're comparing two CSS rules that have the same origin, either two UA styles or two author styles.