Introduction
Utility classes help you quickly style elements without writing new CSS. They save time and keep your code simple.
Utility classes help you quickly style elements without writing new CSS. They save time and keep your code simple.
<element class="utility-class"></element>
mt-3 for margin top or text-center for centering text.class attribute.p-3 utility class.<div class="p-3">Content with padding</div>
text-primary utility class.<p class="text-primary">Blue colored text</p>
<button class="btn btn-success">Green Button</button>
This example uses Bootstrap utility classes to add spacing, colors, and borders quickly without writing custom CSS.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Utility Classes Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-5"> <h1 class="text-center text-primary mb-4">Welcome to Utility Classes</h1> <div class="p-4 bg-light border rounded"> <p class="mb-3">This paragraph has margin below it.</p> <button class="btn btn-danger">Red Button</button> </div> </main> </body> </html>
Utility classes keep your HTML clean and avoid extra CSS files.
They help maintain consistent design by reusing the same classes.
Remember to check Bootstrap documentation for all available utility classes.
Utility classes let you style elements fast without writing CSS.
They are added directly in the HTML class attribute.
Using them speeds up development and keeps code simple.
m for margin and t for top, combined as mt-3.mt-3 matches Bootstrap's utility class naming convention for margin-top spacing.<button class='btn btn-primary p-4'>Click Me</button>
btn-primary applies the primary color style, and p-4 adds padding all around the button.<div class='p-3 mt-5x text-center'>Content</div>
p-3 is valid for padding, text-center is valid for text alignment, but mt-5x is not a valid Bootstrap class.mt-5 without the extra 'x'.d-flex makes a flex container, flex-column stacks children vertically, and flex-lg-row changes direction to row on large screens.Pass the test and this pattern moves unknown