Varun
Varun

Reputation: 109

What is the use of class="container" attribute inside <div> tag in bootstrap?

I have seen many pages having class="container" inside div tag, but what is the use of it? As per what I understand div tag itself is a container then what is the purpose of class="container"?

Upvotes: 2

Views: 2465

Answers (3)

Kody Williams
Kody Williams

Reputation: 1

I was wondering the same thing I am learning Flexbox and I was watching a tutorial and they had a div with a class container that they added to every section and put a width, margin and padding on it. I was wondering if I should be adding a container class every time I make a website

Upvotes: 0

Laraib Aslam
Laraib Aslam

Reputation: 15

actually "container" class contains its own styling that is written in bootstrap class like div is just empty container but "container" class has, for example, 1000px width and also some media queries for mobile-friendly usage responsive designing. the empty div tag does not equal to "container" class.

Upvotes: 1

Neelansh Mathur
Neelansh Mathur

Reputation: 726

You're right in saying that div is a container itself. But, frameworks like Bootstrap have defined their CSS in such a way that you will find different classes everywhere. The container class can be applied to an element other than div too, although div is recommended.

The container class gives your webpage some basic margins and sets it in a way that it is easy to view on all devices.

This is specific to Bootstrap. Other frameworks may use the same name "container" or something else for the same purpose.

Upvotes: 4

Related Questions