Containers in Bootstrap with examples
In bootstrap, container is used to set the content’s margin. It contains row elements and the row elements are container of columns. This is known as grid system.
There are two container classes in bootstrap:
- .container
- .container-fluid
Let’s look at each of the above two class in details with examples:
- .container: The .container class provides a responsive fixed width container.
In the below example, the div with class “container” will have a fixed left and right margin and will not take the complete width of it’s parent or the viewport.
<!-- Bootstrap container class --><html><head><title>Bootstrap Container Example</title><!-- Add Bootstrap Links --><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></head><body><!-- Since we are using the class container, the belowdiv will not take complete width of it's parent. --><divclass="container"style="background: green;"><h1>GeeksforGeeks</h1><p>A computer science portal for geeks.</p></div></body></html>chevron_rightfilter_noneOutput:

- .container-fluid: The .container-fluid class provides a full-width container which spans the entire width of the viewport.
In the below example, the div with class “container-fluid” will take-up the complete width of the viewport and will expand or shrink when ever the viewport is resized.
<!-- Bootstrap container-fluid class --><html><head><title>Bootstrap Container Example</title><!-- Add Bootstrap Links --><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></head><body><!-- Since we are using the class container-fluid, the belowdiv will take-up complete width of the viewport andwill expand or contract whenever the viewport is resized --><divclass="container-fluid"style="background: green;"><h1>GeeksforGeeks</h1><p>A computer science portal for geeks.</p></div></body></html>chevron_rightfilter_noneOutput:
Recommended Posts:
- Bootstrap Buttons with Examples
- Popovers in bootstrap with examples
- Borders in bootstrap with examples
- Spacing in Bootstrap with Examples
- Colors and gradients in bootstrap with examples
- Responsive images in Bootstrap with Examples
- List group in bootstrap with examples
- Flexbox utilities in bootstrap with examples
- Input Groups in Bootstrap with Examples
- Display Property in Bootstrap with Examples
- Vertical alignment in Bootstrap with Examples
- Bootstrap | Float utilities with Examples
- BootStrap | Positioning an element with Examples
- Media Objects in Bootstrap with Examples
- Bootstrap | Sizing an element with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



