Many of the elements come with default styles, which are set by the User Agent's stylesheet (referred to as UA). When you inspect the body
element, you will notice that it already has default properties.
It is important to reset these default properties.
A common practice is to use a Reset CSS file.
For example:
/* Reset CSS */
body, div, section, nav, ... {
margin: 0;
padding: 0;
}
a { text-decoration: none; } /* To remove underlines from all `a` elements */
/* Other reset properties */
How can we use a Reset CSS?
One way is to include it in the head
element:
<head>
<!-- Assuming that reset.css is in the *css folder* -->
<style>
@import url("css/reset.css") screen
@import url("css/style.css") screen
</style>
</head>
Another option is to reference it from your main stylesheet, like so:
/* Style CSS */
@import url("reset.css") screen; /* Assuming style.css and reset.css are in the same folder */
The issue you may be facing in your code is that the body element has a default margin, which you need to reset by adding:
body {
margin: 0;
padding: 0;
}
Here's a DEMO
Best regards,
Leonardo