While the root element html
is stylable by CSS just like any other element, certain properties may behave differently by virtue of it being the root element. position
is one of those properties: in particular the spec has this to say:
User agents may treat position as 'static' on the root element.
As far as I know, no modern browser actually does this, but it's still not guaranteed that position: relative
will always work on the root element. In your case, you can simply avoid this by setting position: relative
on the body
element instead of the html
element:
body {
position: relative;
}
#footer {
position: absolute;
bottom: 0;
left: 0; right: 0;
}
Note that the footer will not stick to the bottom of the page if the body does not reach the height of the viewport (e.g. when there is not enough content in the page). If this is an issue for you, set height
and min-height
on html
and body
following the instructions in my answer here:
html {
height: 100%;
}
body {
position: relative;
min-height: 100%;
}
#footer {
position: absolute;
bottom: 0;
left: 0; right: 0;
}