A bootstrap list group provides the classes to create simple list items as well complex list items using the custom content. You can create list items using custom content like anchor links, buttons, and other contents.
Here is a simple example of Bootstrap List Group:-
- Computer
- Laptop
- Mouse
- Printer
- Keyboard
Let’s see how to create a Bootstrap list group.
Create Simple List Group
To create a basic list group with items, default content is <ul> tag. You need to just add the class .list-group
as the class of the unordered list tag and class .list-group-item
as the class of the list items.
To make first list item active, you have to use the class .active
. See the example below for the basic list group.
1 2 3 4 5 6 7 |
<ul class="list-group" style="width:250px;"> <li class="list-group-item active">Computer</li> <li class="list-group-item">Laptop</li> <li class="list-group-item">Mouse</li> <li class="list-group-item">Printer</li> <li class="list-group-item">Keyboard</li> </ul> |
Output
- Computer
- Laptop
- Mouse
- Printer
- Keyboard
Badges Inside List Group Items
You can also add badges to each list group items by adding <span> tag with class .badge
to each list group item.
See the example below for the badges added to each list group item.
1 2 3 4 5 6 7 |
<ul class="list-group" style="width:250px;"> <li class="list-group-item active"><span class="badge">9</span>Computer</li> <li class="list-group-item"><span class="badge">3</span>Laptop</li> <li class="list-group-item"><span class="badge">20</span>Mouse</li> <li class="list-group-item"><span class="badge">2</span>Printer</li> <li class="list-group-item"><span class="badge">18</span>Keyboard</li> </ul> |
Output
- 9Computer
- 3Laptop
- 20Mouse
- 2Printer
- 18Keyboard
List Groups With Anchor Link Items
You can create bootstrap list group with the items as hyperlinks. To create this list group, you have the include anchor links with class .list-group-item
inside the <div> tag with class .list-group
.
You can also make the anchor list items active using the class .active
. See the example below for the anchor link list group items.
1 2 3 4 5 6 7 |
<div class="list-group" style="width:250px;"> <a class="list-group-item active" href="#.">Mirror</a> <a class="list-group-item" href="#.">Watch</a> <a class="list-group-item" href="#.">Water Bottle</a> <a class="list-group-item" href="#.">Moisturiser</a> <a class="list-group-item" href="#.">Table</a> </div> |
Output
List Group With Button Items
Creating the buttons as the list group items is the easier task using the bootstrap list group classes. Add the button type element with the class .list-group-item
inside the div element with the class .list-group
1 2 3 4 5 6 7 |
<div class="list-group" style="width:250px;"> <button type="button" class="list-group-item active">Mirror</button> <button type="button" class="list-group-item">Watch</button> <button type="button" class="list-group-item">Water Bottle</button> <button type="button" class="list-group-item">Moisturiser</button> <button type="button" class="list-group-item">Table</button> </div> |
Output
Disable List Group Items
To disable a list group item, you need to just add the class .disabled
to the list items which you want to make disabled.
See the below example for the disabled list group items.
1 2 3 4 5 6 7 |
<div class="list-group" style="width:250px;"> <a class="list-group-item disabled" href="#.">Mirror</a> <a class="list-group-item" href="#.">Watch</a> <a class="list-group-item" href="#.">Water Bottle</a> <a class="list-group-item" href="#.">Moisturiser</a> <a class="list-group-item" href="#.">Table</a> </div> |
Output
Hover over the first list group item to see the disabled item. You can see that it will not allow you to click on the list items as it is in a disabled condition.
Create List Group Using Contextual Classes
To create different colored list group items, bootstrap also provides the contextual classes for the Bootstrap list group items.
See the table below with the description for each class.
Class Name | Description |
---|---|
.list-group-item-success |
Used to display success list group item. |
.list-group-item-info |
Specify this class to show information in list group item. |
.list-group-item-warning |
Use this class to specify the warning message in list group item. |
.list-group-item-danger |
Display error message in list group items using this class. |
Now, let us see the example showing the contextual classes for the different colored list group items.
1 2 3 4 5 6 |
<ul class="list-group" style="width:250px;"> <li class="list-group-item list-group-item-success">Success Message item</li> <li class="list-group-item list-group-item-info">Informational Message item</li> <li class="list-group-item list-group-item-warning">Warning Message item</li> <li class="list-group-item list-group-item-danger">Error Message item</li> </ul> |
Output
- Success Message item
- Informational Message item
- Warning Message item
- Error Message item
There are different message types which you can display using the contextual classes given above.
List Group Item with Custom Content
You can also add the other HTML content inside the list group items. Put your heading with its content inside the list group items.
To create an HTML content inside the list group item, put heading with class .list-group-item-heading
and below the heading put your content paragraph using the class .list-group-item-text
.
See the example below to create your own HTML content inside the list group items.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<div class="list-group" style="width:500px;"> <a class="list-group-item active" href="#."> <h4 class="list-group-item-heading">Bootstrap List Group</h4> <p class="list-group-item-text">A list group is the component of bootstrap to create custom list groups with items,</p> </a> <a class="list-group-item" href="#."> <h4 class="list-group-item-heading">Disable Bootstrap List Group</h4> <p class="list-group-item-text">You can use class <code>.disabled</code> to make items disable.</p> </a> <a class="list-group-item" href="#."> <h4 class="list-group-item-heading">Button Bootstrap List Group</h4> <p class="list-group-item-text">You can create list group using the button as list group items.</p> </a> </div> |
Output