← Back to Bootstrap Course | Chapter 4: Colors & Spacing | Lesson 1 of 7

Background के रंग

Background utilities theme इस्तेमाल करके एक element का background colour करती हैं।

In this page:

  1. Background Colors
Syntax
markup
<div class="bg-primary text-white p-3">content</div>
<div class="bg-success-subtle">content</div>

Background Colors

.bg-primary, .bg-secondary, .bg-success, .bg-danger, .bg-warning, .bg-info, .bg-light, और .bg-dark इस्तेमाल करें। .bg-primary-subtle जैसे Subtle variants softer हैं और dark mode support करते हैं। .bg-gradient एक subtle gradient add करता है।

Readable contrast के लिए text-* या text-bg-* के साथ pair करें।

Note: text-bg-primary background और एक readable text colour दोनों set करता है।

उदाहरण: Background colors

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="p-3 mb-2 bg-primary text-white">bg-primary</div>
  <div class="p-3 mb-2 bg-success-subtle text-success-emphasis">bg-success-subtle</div>
  <div class="p-3 mb-2 text-bg-dark">text-bg-dark</div>
  <div class="p-3 mb-2 bg-warning bg-gradient">bg-warning with gradient</div>
</div>
</body>
</html>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. dark backgrounds पर dark text इस्तेमाल करना
  2. text colour changes भूल जाना
  3. standard colours के लिए custom CSS
चैप्टर सारांश
  • bg-{theme} एक background set करता है
  • -subtle variants softer हैं
  • bg-gradient एक gradient add करता है
  • Readable text colours के साथ pair करें
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.