Saltar para o conteúdo principal
O Frontend é um bônus gratuito no CodeMentor AI — o produto principal é Python. Cadastre-se para salvar seu progresso e desbloquear todas as 299 lições de Frontend + 1,100+ lições de Python.Cadastre-se — grátis
← 🎨 CSS as a design system·Módulo B1 · Lição 1
TarefaOverride the default h1 size. Set body margin to 0, and h1 font-size to 48px with color #3B82F6.

De onde vêm os estilos: as três origens

50 XP6 minFREE
Teoria

CSS isn't your stylesheet alone

Every element on a page has a "computed style" — the final answer the browser uses to paint it. That answer is the result of merging styles from THREE origins. For normal (non-!important) declarations the priority is, lowest to highest:

  1. User-agent (browser defaults) — <h1> is bold and 32px because Chrome says so. <a> is blue and underlined. Lists have bullets. Margins exist between paragraphs.
  2. User styles — custom CSS the user applies in browser settings (rare; mostly accessibility). You can ignore this origin for now.
  3. Author styles — your CSS files + <style> blocks + inline style="" attributes. Inline styles are still the author origin, but the cascade has a dedicated step for them: an element-attached declaration beats any normal selector.

`!important` REVERSES the origin order. Important declarations are sorted in their own, upside-down band: important user-agent > important user > important author > normal author > normal user > normal user-agent. So an author's !important beats the author's normal rules, but a user's !important accessibility rule beats the author's !important.

Inside one origin the tie-breakers are, in order: inline style, @layer order, specificity, then source order (last wins). A small specificity note: :is() takes the specificity of its most specific argument, while :where() always contributes zero — handy for low-specificity base styles.

The "starts working from nothing" mistake

Junior devs often look at a default <h1> and wonder "why is this so big?" — they don't realize the browser already gave it 32px and margin. Modern projects ship a reset or normalize stylesheet first:

/* Modern minimal reset */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; }

Two lines that solve 80% of "why does my hero have a tiny gap at the top?"

What this module is about

  • Lesson 2: how the browser PICKS which selector wins (specificity).
  • Lesson 3: which properties cascade from parent → child (inheritance).
  • Lessons 5-7: the box model — content, padding, border, margin.
  • Lessons 8-9: box-sizing: border-box and why it's a default.
  • Lesson 10: capstone combining all the above.
2 separadores
Pré-visualização ao vivo
← À trilhaPróxima lição →

Recebe uma dica de Python ou web por dia — por email

Curto, escrito à mão, sem spam. Cancela a subscrição num clique.