Bootstrap Badges and Labels

Bootstrap Badges

Bootstrap Badges are useful in almost all kinds of different websites now. They are, basically, numerical indicators that help us show the number of items associated a specific link.

For examples, a typical use of badges is to notify the number of unread messages in your inbox.

A basic can be added by using the .badge classes with the <span> element. See the sample code below for illustration:

Bootstrap Button Badge

The example below will tell you how to use badges with some buttons:

Bootstrap Contextual class badge example

Bootstrap badge Pill

Bootstrap badge size

Bootstrap badges with icons

Bootstrap  badges with icons

Bootstrap Labels

The labels are different from badges in the sense that they are generally non-numerical and tells you about the element itself rather than the items it is holding. They can be used for offering tips, counts etc.

The class .label can be used to add labels to your page.

The label colors can also be changed by using the following contextual label classes:

  • label-default
  • label-primary
  • label-success
  • label-info
  • label-warning
  • label-danger

Badges Headings

You can also use Badges with the heading tags (<h1>……<h6>). For this, along with the .badge you also need to use the .badge-secondary class within <span> elements>.

This will help creating rectangular badges.

Contextual Badges

Here’s a list of contextual classes for colored badges:

  • badge-primary
  • badge-secondary
  • badge-success
  • badge-danger
  • badge-warning
  • badge-info
  • badge-light
  • badge-dark

Bootstrap Alerts- Success, Warning, Error, Danger Messages

Alert messages are useful for the websites every now and then.

They might indicate some failed validation or notify a successful registration for the user.

Either way, their appearance is an important aspect to work on.

Bootstrap has many features for Alert Messages as well.

It provides the developers some easy ways in which they can create and style predefined alert messages.

The class, generally, used for the Alerts is the .alert class.

Bootstrap Alert Message Classes

There are the following contextual classes that can be used for different types of alerts:

.alert-primary: This is a primary alert to show information.

.alert-secondary: This is a grey background color alert box to show general information.

.alert-success: This alert message is used to represent a success message.

.alert-danger: Background color – Red. This indicates any dangerous i.e. potentially negative action.

.alert-warning: Background color – Yellow. This is different from alert-danger as this can be used to suggest some caution to avoid any potentially negative action rather than notifying it.

.alert-info: Background color – Light-blue. This is just a piece of information that the user needs to be notified about. Generally, any informative action is indicated using this alert.

.alert-light: This alert box is used to represent data in the light color alert box.

.alert-dark: This alert box represents data in the dark box.

Bootstrap alert messages
Fig: Bootstrap alert messages

Here’s the sample code for using these classes:

Bootstrap success message

Alert css code for bootstrap success message is

<div class="alert alert-success">

Bootstrap info

Alert info CSS is <div class="alert alert-info">

Bootstrap alert warning

We can create alert warnings by including .alert-warning CSS class

<div class="alert alert-warning">

Bootstrap warning color

Bootstrap warning color is FFF3CD in hexadecimal and rgb(255,243,205) in rgb color combination.

Bootstrap alert danger

Alert danger can be created by adding .alert-danger CSS
<div class="alert alert-danger">

Apart from these 4, there are some other classes that can be used for different purposes with alerts. Let’s have a look

Bootstrap error message

We can use bootstrap alerts for error messages .alert-warning and .alert-danger can be used to show normal and critical error messages.

Bootstrap Alert Links

You can add some matching links with matching foreground and background colors using the .alert-link class.

These links can be used to redirect the user to some detailed information about the alert.

Bootstrap Closing Alerts

In some cases, the user may want to remove the alert ones they have addressed it.

This can be done by using dismissible or closable alerts.

In order to do this you can use the .alert-dismissible class to the alert container.

You also need to add class="close" and data-dismiss="alert" to some link or a button element.

Therefore, when you click on this element the alert box will disappear.

Here’s the code to understand this better:

Observe the ‘aria-label’ and ‘&times’ in the above code. 

These two have an important role in this code. The aria-label= “close” attribute is there to have a better accessibility for the close button.

The ‘&times’ or the (×) is actually a better and more preferable way of indicating the close button instead of using the ‘x’ symbol.

Bootstrap Animated Alerts

The two classes used to add an animated fade effect for when closing the alert messages are .fade and .in.

Bootstrap Close Alerts via data-* Attributes

Another way of creating a dismissible alert is by using the data-dismiss="alert" attribute to any link or button element.

Just like the .alert-dismissible class, this too shall close the alert message using the link/button element.

Bootstrap dismissable alert

Bootstrap alert fade out

Bootstrap Tables-striped, border, hover, responsive

Here we will discuss various ways in which Bootstrap can help the developers to make the tables look perfect on the web pages.

Bootstrap table styles

All Table styles are inherited in bootstrap4.

using CSS classes we can create a simple, striped, bordered table.

Can add the hover effect. easily include colors in rows and columns.

let’s see them one by one

Bootstrap table basic

Let us start with the basic table in bootstrap. Here the design is minimal with light padding and only horizontal dividers.

bootstrap table basic

The class used for the basic table is .table. Here’s a sample code for the same:

Bootstrap table striped

 Bootstrap table striped

To add zebra stripes to your table you can use the .table-striped class. Here’s the sample code

Bootstrap table border

For adding table borders, Bootstrap has provided the .table-bordered class. This will add borders at all sides of the table and cells.

Bootstrap table border

Observer the below code:

Bootstrap table hover

To give a special effect on hover, we can use the .table-hover class. The following code illustrates the same

Sr NoTableExample
1Simple Table Try It
2Striped Table Try It
3Border Table Try It

Bootstrap table condensed

The .table-condensed class will help make a table compact, by cutting cell padding in half.

See the code below for a better understanding

Bootstrap Contextual Classes with table

Contextual classes are special classes that can be used to the color table rows/table cells (<td>).

Bootstrap Contextual Classes with table

Here is a list of contextual classes provided by Bootstrap:

  • .active: To apply the hover color to the table rows or table cell
  • .info: To indicates neutral informative change of action
  • .success: To show a successful or positive action
  • .danger: To show some dangerous (potentially negative) action
  • .warning: Indicates a warning that might need attention

Bootstrap responsive tables

Responsiveness is an indispensable feature of Bootstrap for any web page element.

In the case of tables, responsiveness can be achieved using the .table-responsive class.

This makes the table horizontally scrollable on any device with screen width less than 768px.

However, there is no considerable change in devices with a screen size larger than 768px.

.table class is used with .table-responsive{-sm|-md|-lg|-xl} classed

Following is a sample code for responsive tables in Bootstrap:

Bootstrap 4 table example

Above all, we have seen basic examples of table all are compatible with bootstrap 4.

Let us see one more example

How to show names of students and branches in the table.

Bootstrap table header color

to set table header color use contextual classes as below.

<th class="table-success">
<th class="table-danger">
<th class="table-info">
<th class="table-warning">

Bootstrap table row color

use contextual classes with <tr> it will add color to specified table row.

<tr class="table-success">
<tr class="table-danger">
<tr class="table-info">
<tr class="table-warning">


Bootstrap table column width

Bootstrap table without borders

Creating a table without a border is possible with bootstrap. To make a borderless table use class .table-borderless

How to make a table responsive

to make a table responsive use .table class with .table-responsive{-sm|-md|-lg|-xl}.

Bootstrap Images

Here we will study about how what Bootstrap 4 has in store for the image elements of your web pages.

Bootstrap 4 images Shapes

Using Bootstrap, the images can be rendered in the following three shapes:

  • Rounded Corners:
  • Circle
  • Thumbnail

Out of these three, the first two are not supported by IE8 or earlier versions

Bootstrap Rounded Corners images

For rounded corners, you can use the .rounded class with your <img> tag.

For example:

Circle images in bootstrap

Adding the .rounded-circle class to <img> the tag will shape your image into a circle.

For example:

Thumbnail images bootstrap

The thumbnail shape can be achieved using the .img-thumbnail class.

For example:

Bootstrap images responsive

The sizes of the images and screens might not go hand-in-hand more often than you can predict.

We need to have responsive images that can automatically adjust as per the size of the screen.

We can make the images responsive using the class. .img-fluid class with the <img> tag.

Now, the image will, nicely, scale to the parent element.

When using .img-fluid class the display is automatically set to block and max-width to 100%. Similarly, height is set to auto as well.

See the code below for example:

Bootstrap Images Gallery

The image gallery can be created by using Bootstrap’s grid system along with the .thumbnail class.

The code below illustrated the same:

Bootstrap Responsive Embeds

Not only the images but the other embedded media like videos and slideshows can also be made responsive to scale properly on any device.

For this, you need to add the class embed-responsive to any <div> item.

You will also need to add the .embed-responsive-item to your <iframe>, <embed>, <video>, and <object> elements.

What is aspect ratio?

The aspect ratio of any image can be described as the proportional relationship between the image’s width and height.

The most common video aspect ratios we have are 4:3 which was a universal video format of the 20th century and 16:9 that is commonly known for the HD television.

We have two classes for these aspect ratios in Bootstrap:

  • embed-responsive embed-responsive-4by3
  • embed-responsive embed-responsive-16by9

Bootstrap <img> Classes

Bootstrap has the following classes for styling your image elements

  • .rounded: To add rounded corners to the image
  • .rounded-circle: To shapes the image into a circle
  • .img-thumbnail: To shape the image into a thumbnail
  • .img-fluid: To make the image responsive make it scale nicely to the parent element.

Bootstrap center images

Block-level images can be centered using .mx-auto

bootstrap images in a row

Bootstrap image gallery

Good Reference image Gallery
See Multiple Gallery

Bootstrap images side by side

Create a row and divide the row into columns inside column insert image.

This will display images side by side

How to make images responsive in bootstrap

To make images responsive in bootstrap use .img-fluid class

Bootstrap background image

Showing image in background is very simple

use background-image: url(..) css property with url.

Example of background image is as below

Bootstrap Media Objects

The media objects (like images or videos) on the web page need to be aligned properly to stand out but not completely out of context.

HTML and CSS have their own features to provide the required positioning to the media objects on the webpage.

Bootstrap makes it much easier for the developers to align these media objects as per the content and webpage styling.

With Bootstrap, the media objects can be aligned to the left or to the right of the content.

Such alignments styles are useful for blog comments or tweets where both text and pictures are displayed for multiple users.

Bootstrap Media Example
Fig: Bootstrap Media Example

Basic Bootstrap Media Object

Let’s have a look at a sample code for the Left and right alignment of the media object.

Observer the code followed by the explanation:

Bootstrap Media Left and Right Alignment

Bootstrap Media Left and Right Alignment


  • The <div> element is being used with with the .media class here. This will create a container for media objects to be used.
  • As for the alignment, we use the appropriate class for the required aligning direction Therefore the .media-left class will be used to align the media object (image in this case) to the left and similarly, .media-right class is there to to align it to the right.
  • The class= “media-body” is also used with a container in the code. This is to align the text next to the image.
  • Furthermore, the .media-heading can be used for the headings.

Media bootstrap top, middle or bottom alignment

Not just horizontally, we can also set vertical alignments for the media objects.

There are basically three vertical alignments that we generally use in different containers:

  • Top: Media object aligned at the top corner of the content
  • Bottom: Media object aligned bottom corner of the text content
  • Middle: Media object aligned adjacent to vertically middle of the text content

In Bootstrap, these alignments can be made using respectively the classes align-self-start, align-self-centre and align-self-end.

Media bootstrap top, middle or bottom alignment
Fig: Bootstrap media alignment

Here’s a sample code for the vertical alignment of the media objects

Nested media object bootstrap

You can also have nested media objects using bootstrap.

These are quite common on social websites these days.

For example, the ‘replies to the comment’ options in websites like Facebook, Twitter, Instagram, etc.

Have employed the nested media object style for their media object positioning.

Nested media object bootstrap
Fig: Nested media object bootstrap

Bootstrap Containers- container and container-fluid classes

Here, we will check out the Containers, one of the most basic web page layouts employed by Bootstrap to design the web pages.

But before we move into that, let us first understand what a layout is and how a typical layout is made to come to real-world page.

Bootstrap Responsive Webpage Layout

A webpage layout is basically the template that helps you understand the sizing, positioning, and styling of all its components.

More or less, every layout takes care of the following points:

  • Header: The top part of the webpage. It usually contains your website’s logo or name.
  • Navigation Section: This is the section of the page where all the Navbars are present. These can be normal navigation menus or drop-down carrying sub-menu of the selected menus.
  • Content Section: The content section contains all the necessary stuff for that web page.
  • Footer: The footer section of the web-page generally contains links to official stuff about the website or web application. You can find the links for Privacy Policy, About Us and Available Downloads from this part of the page.

This is the basic layout of any web page you’ll come across. A code below will show you a typical web page using the above-mentioned layout:

Bootstrap Responsive Webpage Layout
Fig: Bootstrap Responsive Webpage Layout

Bootstrap Container

The Bootstrap container layout is one of the most basic layouts for a webpage.

When you’re using the grid-system for your webpage, the Bootstrap Container layout can help you the best.

Above-mentioned we’ll have to choose from fixed-width/ fluid-width, responsive containers that suit best for our webpage vision.

div class container

The code below will illustrate the Bootstrap container’s usage on the web page:

Bootstrap container background color

Bootstrap container background color
Bootstrap container background color

Try these background colors

Sr NoBackground ColorRun It
1bg-primaryTry It
2bg-secondaryTry It
3bg-successTry It
4bg-dangerTry It
5bg-warningTry It
6bg-infoTry It
7bg-lightTry It
8bg-darkTry It
9bg-whiteTry It

Bootstrap container fluid class

You can also use .container-fluid for using a full-width container that will span the entire width of the viewport.

Your div element should have the class container-fluid

To create the class as container-fluid use this with div as below

Which class in bootstrap make container full width

.container-fluid class in bootstrap make container full width

Difference between container and container fluid

The .container has fixed width for each screen size.

The .container-fluid has full width (100%) for each screen size.

Bootstrap 4 Grid System

The grid system in Bootstrap 4 is built using flexbox. It allows a maximum of 12 columns across the web page.

In case you do not need to use all the 12 columns available, you can group individual columns to get wider columns for your usage.

Bootstrap 4 Grid System
Fig: Bootstrap 4 Grid System
Bootstrap 4 Grid System
Fig: Bootstrap 4 Grid System

Due to the responsiveness of the grid system, the columns get re-arranged automatically as per the screen size of the operating device.

Bootstrap nested columns example

Bootstrap nested columns example
Fig: Nested columns example

Bootstrap Grid Classes

Here’s the list of the classes available for Bootstrap’s grid system:

.col – It is for very small devices that have a screen width of less than 576px

.col-sm– This is for the devices having screen width equal to or greater than 576px

.col-md – The range of medium size devices can use this class. the screen width has to be equal to or greater than 768px)

.col-lg – This class is for the devices that have screen widths equal to or greater than 992px

.col-xl – Used for very large devices that have screen width equal to or greater than 1200px

Sr NoCSS ClassExample
1.col Try It
2.col-sm Try It
3.col-md Try It
4.col-lg Try It
5.col-xl Try It

For more creating more dynamic and flexible layouts, the above-listed classes can be combined appropriately.

Please note that since each class scales up, so if you want to set the same width for md as for sm, you just have to specify the above-listed.

Bootstrap column classes basic structure

Take a look at the basic structure of the Bootstrap 4 grid:

Explanation for the First example:  Here we are creating a row (<div class="row">).

Then we added the required columns using suitable .col-*-* classes.

Here the first star (*) tells you the responsiveness i.e. sm, md, lg or xl, the second star, furthermore, represents a number.

This number should ad upto 12 for any given row.

Explanation for Second example: In the second example, instead of adding a number to each col we will let the layout be handled by the bootstrap.

Thus, for equal width columns we have: two “col” elements = 50% width each and three cols = 33.33% width each and so on.

The responsiveness of the columns can be set as per the requirements.

Here are some more examples for different column requirements:

Bootstrap grid examples

Bootstrap 12 column grid

Bootstrap 12 column grid
Fig: Bootstrap 12 column grid

Bootstrap Grid Three Equal Columns

Bootstrap Grid Responsive Columns

The following example will demonstrate, how you can create four equal-width columns.

These will start at tablets and will then scale to extra-large desktop screens.

Responsive columns can be used with devices whose screens width are less than 576px like mobile, the above columns will get stacked on top of each other, automatically.

Bootstrap two column Unequal Responsive Grid

Another example with columns scaling from the tablet screens to extra-large desktop screens. Furthermore, the columns here, will have varied width.

Thus, depending on the requirement, you can use the Bootstrap grid system to provide responsive columns for different devices.

How to put divs next to each other

Bootstrap column resolves this problem.

create a new row and inside row create columns

Bootstrap offset left Example

To create offset we use class offset-*-*.

for small devices it is offset-sm-1

Bootstrap offset left Example
Fig: Bootstrap offset left Example

Bootstrap columns not side by side

To create columns we use .col class these .col must be inside .row class otherwise it will not show columns side by side

The correct way to place .col is as below

Bootstrap padding/margin between columns

offset-* can be used to provide space between columns

Bootstrap padding/margin between rows

bootstreap4 uses following properties for margin and padding

m- for margin
p- for padding

it is used with

t- set margin-top or padding-top
b-set margin-bottom or padding-bottom

with size property

0- margin and padding set to 0
1- margin and padding set to 1

Bootstrap 4 Tabs Pills Navs with Examples

Bootstrap 4 Tabs Pills Navs are very useful part in web application.

Lets discuss them one by one

Bootstrap 4 nav menu

The navigation bar can be styled in various ways using Bootstrap 4.  here we will look at some sample codes for styling the Navs as per different style requirements.

Bootstrap 4 Horizontal Navbar

For creating a simple horizontal nav menus, you can just add the .nav class with a <ul> tag, followed by .nav-item for each <li> and add the .nav-link class to their links:

bootstrap 4 nav classes

The .justify-content-center the class centers the nav, while the .justify-content-end class right-aligns it.

Vertical navbar bootstrap 4

The .flex-column the class creates a vertical nav:

Vertical menu bar in bootstrap example

Bootstrap 4 tabs

.nav-tabs the class turns the nav menu into navigation tabs.

Bootstrap 4 pills

.nav-pills class  to make Navigation pills

Justified Tabs/pills

.nav-justified class justifies the tabs/pills

Tabs with Dropdown

Pills with Dropdown

As mentioned in above code change class to nav-pills

Toggleable / Bootstrap dynamic tabs

For making the tabs toggle-able you can add the data-toggle="tab" attribute with each link.

After that, add a .tab-pane class along with a unique ID attached to the tab.

Wrap them all inside a <div> element with the .tab-content class.

The tabs can also be styled to fade in or fade out when you click on them. To add this, add the .fade class to .tab-pane:

Toggle-able / Dynamic Pills

Just like the dynamic tabs you can apply the code to pills. Therefore, all you need to do is change the data-toggle attribute to data-toggle=”pill”:

Bootstrap 4 vertical tabs responsive

Bootstrap 4 vertical tabs responsive

which of the following bootstrap styles are used to create a vertical pills navigation?

a) .nav-stacked b) .nav-pills c) .nav-justified d) .tab-pane

.nav-stacked is used to create vertical pills navigation.

Also Read

Bootstrap Containers

Read More


Bootstrap Sizing

Bootstrap has a separate set of utilities for controlling the size of the element.

You can manage the width and height of the element as per the requirement.

Here, we will talk about the Boostrap Sizing utilities and discuss the various Bootstrap classes for the same.

, we will talk about the Bootstrap Sizing utilities and discuss the various Bootstrap classes for the same.

To understand the working better, we can first have a look at the CSS sizing properties.

These properties are used to control the normal height and width as well as maximum height and width.

So let’s have a look at the CSS sizing properties before we dive in to the Bootstrap concepts.

CSS Properties

CSS has following properties to control the sizing of the components:

  • height: For controlling the height of the element
  • max-height: For setting the maximum height of the element
  • max-width: For setting the maximum width of the element
  • min-height: For setting the minimum height of the set the element
  • min-width: For setting the minimum width of the element
  • width: For controlling the width of the element

Check the code below to get a good understanding of these properties:

HTML body contains

Now that, you understand the basic sizing features in CSS. Let us get back to Bootstrap.

Bootstrap Sizing

Bootstrap lets you easily control the elements for its width or its height.

You can set these parameters relative to the parent components. Let’s check out some points that you need to know for Bootstrap Sizing utilities:

  • You can manage the width and height of the components using the $sizes Sass map present in the _variables.scss.
  • For width, we have the w-* classes and height we have the h-* classes. Where the * is replaceable by appropriate numbers
  • By default, Bootstrap supports the sizing for 25%, 50%, 75%, and 100%. Therefore, the * in the above point can be replaced with 25, 50, 75 or 100.

Modify those values as you need to generate different utilities here

Max-Width and Max-Height

Similarly, the max-width and max-height properties of CSS can also be controlled by following bootstrap clases:

  • mw-*: Sets the maximum width with the * value.
  • mh-*: Sets the maximum height with the * value.

The below code will illustrate the use of these classes to control the maximum width and height for the value of 100%

Java program to print vowels in a String

In Java, String is represented as an Object.

String characters are represented in Unicode encoding.

In the English language, there are five vowels a, e, i, o, and u.

In any string, vowels can be in small or in large letters.

Here using the Java program we will see how to find vowels in the given string.

Vowels program in java

Vowel program in java are discussed as follows

We created many programs to check and count vowels and consonants from String, StringBuffer, and from files.

Java program to print vowels in a String is as below

Java program to print vowels in a String

Steps to develop the program

  1. Take a String
  2. Create a loop to iterate each character of the string
  3. Inside loop check characters for vowel, both for upper and lower case
  4. If the character is a vowel then print its position and character

In the above program, we created for loop and it runs up to string length.

charAt() is used to access characters at specified index position.

The above program is simple we can make some improvements to it.

We are comparing both uppercase and lower case, we can convert complete string in lower case and compare it will reduce all uppercase comparison.

How to find vowels in a string in java

Java program to count number of vowels in a string from File

test.txt file is stored in d drive and file content is as below.

The Scanner class is used to read test.txt file.

Vowels program in java using switch case

Q: write a program to determine whether the input character is a vowel or consonant or not an alphabet

program to count the number of vowels and consonants in a given string in java

Character class contains method isAlphabetic.

This method is checking whether a number is an alphabet or not.

If the number is alphabet then match the character using for each loop with vowel characters stored in the array.

If matched then the character is vowel else consonant.

Java program to replace vowels in a string