Bootstrap

Boootstrap CSS Helpers

Bootstrap 5 Helper (Utility) Classes


1. Spacing Helpers

Control margin and padding with shorthand classes:

  • Format: .m{side}-{size} or .p{side}-{size}

  • m = margin, p = padding

  • side = t (top), b (bottom), s (start/left), e (end/right), x (left & right), y (top & bottom), or blank (all sides)

  • size = 0 to 5 or auto

Examples:

html
<div class="mt-3">Margin top 1rem</div>
<div class="px-2">Padding left and right 0.5rem</div>
<div class="m-auto">Auto margin (center horizontally in flex or grid)</div>

2. Text Helpers

  • .text-center, .text-start, .text-end — text alignment

  • .text-wrap, .text-nowrap, .text-truncate — control text wrapping and truncation

  • .text-lowercase, .text-uppercase, .text-capitalize — transform text case

  • .text-muted — muted gray text

  • .text-reset — reset color to inherited

Example:

html
<p class="text-uppercase text-center text-muted">Sample text</p>

3. Display Helpers

Control element display and visibility:

  • .d-none, .d-inline, .d-inline-block, .d-block, .d-grid, .d-flex, .d-inline-flex

  • Responsive variants: .d-{breakpoint}-none, .d-{breakpoint}-block, etc.

  • .visible — visible

  • .invisible — invisible but takes up space

Example:

html
<div class="d-none d-md-block">Hidden on small, visible on medium+</div>

4. Flexbox Helpers

Quick flex utilities:

  • .flex-row, .flex-column, .flex-row-reverse, .flex-column-reverse

  • .flex-grow-0, .flex-grow-1

  • .flex-shrink-0, .flex-shrink-1

  • .justify-content-start, .justify-content-center, .justify-content-end, .justify-content-between, .justify-content-around, .justify-content-evenly

  • .align-items-start, .align-items-center, .align-items-end, .align-items-baseline, .align-items-stretch

  • .align-self-auto, .align-self-start, .align-self-center, .align-self-end, .align-self-baseline, .align-self-stretch

Example:

html
<div class="d-flex justify-content-between align-items-center">
<!-- flex items -->
</div>

5. Position Helpers

Positioning utilities:

  • .position-static, .position-relative, .position-absolute, .position-fixed, .position-sticky

  • Position offsets: .top-0, .bottom-0, .start-0, .end-0

  • Transforms: .translate-middle, .translate-middle-x, .translate-middle-y

Example:

html
<div class="position-absolute top-0 end-0">Positioned top-right</div>

6. Sizing Helpers

Control width and height:

  • Width: .w-25, .w-50, .w-75, .w-100, .w-auto

  • Height: .h-25, .h-50, .h-75, .h-100, .h-auto

  • Max-width: .mw-100

  • Max-height: .mh-100

Example:

html
<img src="image.jpg" class="w-50 h-auto" />

7. Border Helpers

  • .border — add border

  • .border-top, .border-end, .border-bottom, .border-start

  • .border-0 — remove all borders

  • .border-{color} — color the border (e.g., .border-primary)

  • .rounded, .rounded-circle, .rounded-pill, .rounded-0 — border radius

Example:

html
<div class="border border-primary rounded p-3">Box with blue border and rounded corners</div>

8. Shadow Helpers

  • .shadow — small shadow

  • .shadow-sm — smaller shadow

  • .shadow-lg — larger shadow

  • .shadow-none — no shadow

Example:

html
<div class="shadow p-3 mb-5 bg-white rounded">Box with shadow</div>

9. Overflow Helpers

  • .overflow-auto

  • .overflow-hidden

  • .overflow-visible

  • .overflow-scroll


10. Visibility Helpers

  • .visible

  • .invisible — invisible but occupies space


11. User Select Helpers

Control text selection behavior:

  • .user-select-none

  • .user-select-auto

  • .user-select-all


Quick Example Combining Helpers

html
<div class="d-flex justify-content-center align-items-center vh-100">
<button class="btn btn-primary m-3 p-3 shadow rounded">Click Me</button>
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *