div tag defines a division or a section in an HTML document that is used as a container to hold other HTML elements. It occupies more space than its contents and looks larger than its contents. We can make a div that is not larger than its contents using the following two CSS properties:
If we apply any one of the above CSS properties to
div tag, then the
div will not be larger than its contents.
In the HTML tab:
In the CSS tab:
We apply background color to all three
div tags so that we can distinguish the space they use.
We can observe from the output that the first
div is larger than its contents. However, the
div tags which have CSS properties applied to them perfectly encapsulate their contents with no extra space.
View all Courses