The .ml-auto class in Bootstrap can be used to align navbar items to the right. The .ml-auto class automatically aligns elements to the right. In this article, we will align the navbar to the right in two different ways, below both the approaches are discussed with proper example.
Example 1: In the first example, we use the .ml-auto class of Bootstrap 4 to align navbar items to the right. The .ml-auto class automatically gives a left margin and shifts navbar items to the right.
- Program:
<!DOCTYPE html><html><head><!-- Including the bootstrap CDN --><linkrel="stylesheet"href=<scriptsrc=</script><scriptsrc=</script><scriptsrc=</script></head><body><!-- Creating a navigation bar using the.navbar class of bootstrap --><navclass="navbar navbar-expand-sm bg-light"><ulclass="navbar-nav ml-auto"><liclass="nav-item"><aclass="nav-link"href="#">About</a></li><liclass="nav-item"><aclass="nav-link"href="#">Contacts</a></li><liclass="nav-item"><aclass="nav-link"href="#">Settings</a></li></ul></nav></body></html>chevron_rightfilter_none - Output:

Example 2: In this example, we do not use any pre-defined Bootstrap 4 class to align the items. In this example, we create a navbar and then using CSS gives the left margin as an auto which shifts the navbar items to the right.
- Program:
<!DOCTYPE html><html><head><!-- Including the bootstrap CDN --><linkrel="stylesheet"href=<scriptsrc=</script><scriptsrc=</script><scriptsrc=</script><style>.navbar-nav {margin-left: auto;}</style></head><body><!-- Creating a navigation bar using the.navbar class of bootstrap --><navclass="navbar navbar-expand-sm bg-light"><ulclass="navbar-nav"><liclass="nav-item"><aclass="nav-link"href="#">About</a></li><liclass="nav-item"><aclass="nav-link"href="#">Contacts</a></li><liclass="nav-item"><aclass="nav-link"href="#">Settings</a></li></ul></nav></body></html>chevron_rightfilter_none - Output:

Recommended Posts:
- How to Align Navbar Items to Center using Bootstrap 4 ?
- How to Align navbar logo to the left screen using Bootstrap ?
- Difference between align-content and align-items
- How to design full width dropdown Navbar using Bootstrap ?
- How to Set navbar active class with Bootstrap and AngularJS ?
- Creating Navbar | Vanilla HTML CSS Vs Bootstrap
- How to align button to right side of text box in Bootstrap?
- How to set hamburger items on the right in bootstrap 4 ?
- CSS | align-items Property
- How to use Bootstrap to align labels with content into 4 columns ?
- How to align buttons in Card footer in Bootstrap ?
- How to align header with wrapper in Bootstrap ?
- How to create an Affix or sticky Navbar ?
- How to create Animated Blur Navbar using CSS?
- How to set sticky navbar only for first section of page?
- How to align flexbox columns left and right using CSS ?
- How to put items underneath each other flex box in Bootstrap 4 ?
- Include Bootstrap in AngularJS using ng-bootstrap
- Difference between bootstrap.css and bootstrap-theme.css
- Difference Between Bootstrap 3 and Bootstrap 4
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.

