Bootstrap 4 contextual background utilities quickly apply semantic background colors. Pair dark backgrounds with a readable text utility when needed.
<div class="bg-primary text-white">Primary</div>
<div class="bg-success text-white">Success</div>
<div class="bg-warning text-dark">Warning</div>
<div class="bg-danger text-white">Danger</div>
<div class="bg-light text-dark">Light</div>
<div class="bg-dark text-white">Dark</div>
<div class="bg-white text-dark">White</div>
<div class="bg-transparent">Transparent</div>
const classes =
"bg-primary bg-success bg-warning bg-danger bg-info bg-light bg-dark";
$( "#box" )
.removeClass( classes )
.addClass( "bg-success text-white" );
$( "#box" ).css(
"background-color",
"#e9ecef"
);
<p class='bg-primary'>This Background is class='bg-primary' Hex : '#337ab7'</p>
<p class='bg-success'>This Background is class='bg-success' Hex : '#c1e2b3'</p>
<p class='bg-info'>This Background is class='bg-info' Hex : '#d9edf7'</p>
<p class='bg-warning'>This Background is class='bg-warning' Hex : '#f7ecb5'</p>
<p class='bg-danger'>This Background is class='bg-danger' Hex : '#f2dede'</p><h3 class="bg-danger">This background is class='bg-danger'</h3>.hdd{padding-left: 0.3cm;}class='bg-warning text-dark hdd'<style>
.my_bg-class {
background-color: #f00000;
}
</style><p class="my_bg-class">This background is class='my_bg-class'</p><style>\n";
str +=".my_bg-class {\n";
str +=" background-color: "+val+";\n"
str +="}\n"
str +="</style>var presentClassName = $('#d1').attr('class');$('#d1').removeClass('bg-warning').addClass( 'bg-info' );var presentClassName = $('#d1').attr('class');
$('#d1').removeClass( presentClassName).addClass( "bg-success" );
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.