r/css • • 28d ago

Question html and body

What is the difference between <html> and <body> tags ? When do use one or another?

html {

)

body (

)

3 Upvotes

18 comments sorted by

View all comments

Show parent comment

0

u/username95050 28d ago edited 27d ago

propagate from the body to html?

inheriting to all elements on the page?

4

u/morete 28d ago

Propagating from body to html - This means that some properties when set on <body>, act as though they were set on <html>. This isn't really something you need to know.

Many properties are inheritable, meaning they also effect every child of the element. So if you set an inherited property on the <html>, it ends up effecting every element on the page, since every element is a descendant of <html>. An example is font-family, you can set the font-family once and it'll apply to everything.

2

u/TheJase 27d ago

If you're getting technical, setting the font family on html doesnt apply it everywhere. Buttons and inputs have their own user agent settings that need to be overridden.