Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
Bootstrap 5 Sizing
Next article icon

Bootstrap 5 Sizing

Last Updated : 04 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bootstrap 5 Sizing utility classes adjust element dimensions relative to the viewport or parent container. Options include percentage-based widths, and viewport-relative dimensions, facilitating responsive design for flexible layouts across various screen sizes.

Bootstrap 5 Sizing Classes

Class NameDescription
Relative to the ParentSets the height and width of the element relative to its parent.
Relative to the ViewportSets the height and width of the element relative to the viewport.
SassSass sizing utilities declared in the Utility API.

Syntax:

<div class="w-25">      ...  </div> 

Examples of Bootstrap 5 Sizing

Example 1: In this example, we used the sizing classes relative to the parent to set the height and width of the element.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta http-equiv="X-UA-Compatible"          content="IE=edge">     <meta name="viewport" content= "width=device-width, initial-scale=1.0">     <title>Bootstrap 5 Sizing</title>      <!-- Bootstrap CSS -->     <link rel="stylesheet" href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />      <!-- Bootstrap Javascript -->        <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js">     </script> </head>  <body>     <div class="container">         <div class="my-4">                          <strong>Bootstrap 5 Sizing</strong>         </div>          <h5>Relative to Parent Width</h5>         <div class="bg-dark">             <div class="w-100 p-2 mb-2                  text-bg-success">                 Width = 100% of the parent             </div>             <div class="w-auto p-2 mb-2 text-bg-success">                 Width = auto</div>             <div class="w-25 p-2 mb-2 text-bg-success">                 Width = 25% of the parent</div>             <div class="w-50 p-2 mb-2 text-bg-success">                 Width = 50% of the parent</div>             <div class="w-75 p-2 mb-2 text-bg-success">                 Width = 75% of the parent</div>         </div>          <h5>Relative to Parent Height</h5>         <div class="bg-dark" style="height:200px;">             <div class="h-100 w-auto p-3 text-bg-success                  d-inline-block">100% Height</div>             <div class="h-50 w-auto p-3 text-bg-success                  d-inline-block">50% Height</div>             <div class="h-25 w-auto p-3 text-bg-success                  d-inline-block">25% Height</div>             <div class="h-auto w-auto p-3 text-bg-success                  d-inline-block">Auto Height</div>             <div class="h-75 w-auto p-3 text-bg-success                  d-inline-block">75% Height</div>         </div>     </div> </body>  </html> 

Output:

BootstrapSizing-(1)
Bootstrap 5 Sizing Example Output

Example 2: In this example, we used the sizing classes relative to the viewport to set the height and width of an element.

HTML
<!DOCTYPE html> <html lang="en">     <head>         <meta charset="UTF-8" />         <meta             http-equiv="X-UA-Compatible"             content="IE=edge"         />         <meta             name="viewport"             content="width=device-width,                       initial-scale=1.0"         />         <title>Bootstrap 5 Sizing</title>          <!-- Bootstrap CSS -->         <link             rel="stylesheet"             href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"         />          <!-- Bootstrap Javascript -->         <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js">          </script>     </head>      <body>         <div class="container">             <div class="my-4">                 <strong                     >Bootstrap 5 Sizing</strong                 >             </div>              <h5>                 Relative to Viewport Height And                 Width             </h5>              <div                 class="min-vw-100                         p-3                         text-bg-success                         d-inline-block"             >                 Min VW 100             </div>             <div                 class="vw-100 mt-3                         p-3 text-bg-success                         d-inline-block"             >                 VW 100             </div>             <div                 class="min-vh-100                         mt-3 p-3                         text-bg-success                         d-inline-block"             >                 Min VH 100             </div>             <div                 class="vh-100 p-3                         text-bg-success                         d-inline-block"             >                 VH 100             </div>         </div>     </body> </html> 

Output:

Bootstrap 5 Sizing Example Output

Next Article
Bootstrap 5 Sizing

V

vpsop
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • Bootstrap
  • Technical Scripter 2022
  • Bootstrap-5

Similar Reads

    Bootstrap 5 Cards Sizing
    Bootstrap Cards Sizing refers to the ability to control the dimensions of cards in Bootstrap by using predefined classes such as col, col-sm, col-md, col-lg, col-xl, and col-xxl. This ensures consistency and responsiveness across various screen sizes, maintaining a uniform appearance for card elemen
    2 min read
    Bootstrap 5 Spacing
    The spacing utility is used to assign responsive-friendly margin or padding values to an element or a subgroup of its sides. Padding is the area inside of any div or container, as opposed to a margin, which is the area outside of it. Margin and Padding can be added by adding Bootstrap classes in an
    3 min read
    Bootstrap 5 Select Sizing
    Bootstrap 5 Select Sizing is used to choose form's select small and large custom selects to match your different-sized text inputs. The large-sized select element used the class form-select-lg and the small-sized select uses the form-select-sm class. Bootstrap 5 Select Sizing Class: The default size
    2 min read
    Bootstrap 5 Dropdowns Sizing
    Bootstrap 5 Dropdowns Sizing is used to create dropdowns on different sizes of buttons. It normally works on any size of a button, there can be a single large button or a split small button. Bootstrap 5 Dropdowns Sizing Class: There is no pre-defined class for this you can use the Bootstrap 5 Dropdo
    2 min read
    Bootstrap 5 Spacing Gap
    The spacing utility is used to assign responsive-friendly margin or padding values to an element or a subgroup of its sides. When the display is set to grid, you can use gap utilities on the parent grid container. With responsive gap utilities, you don’t have to add margin utilities to individual gr
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences