Bootstrap color picker
Posted by Superadmin on April 30 2023 16:55:06

Bootstrap color picker

Bootstrap color picker

Introduction to Bootstrap color picker

The bootstrap color picker is an advanced bootstrap plug-in used to choose color and color code. The bootstrap color code has categorized in three types which is “RGB”, “HSL”, and “hex” these color picker helps to recognize types of color code. It helps to change the theme of color, background, and component color in the websites and web applications. The color picker allows users to change the front part of the web application as per your requirement and choose.

Syntax

<div class="container">
<input id = "Id_name" type = "text"  />
</div>
<script>
$(function () {
$('#Id_name').colorpicker();
});
</script>

How to Create Color Picker in Bootstrap?

<meta name = "viewport" content = "width=device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.js" > </script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.min.js" > </script>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.min.css"/>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.css"/>
<div class="container">
<input id = "color-picker" type = "text" />
</div>
<script>
$(function () {
$('#color-picker').colorpicker();
});
</script>
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap color picker Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.js" > </script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.min.js" > </script>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.min.css"/>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.css"/>
</head>
<body>
<h2> Bootstrap Color Picker </h2>
<div class = "container">
<input id = "color-picker" type = "text" placeholder = "find color code" />
<script>
$(function () {
$('#color-picker').colorpicker();
});
</script>
</div>
</body>
</html>

Examples

Different examples are mentioned below:

Example #1

The color picker with display hex and RGB color code example and output.

Code:

<!DOCTYPE html>
<html>
<head>
<title> Bootstrap color picker Example </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.js" > </script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.min.js" > </script>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.min.css"/>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.css"/>
</head>
<body>
<h2> Bootstrap Color Picker </h2>
<div class = "container">
<input id = "color-picker1" type = "text" placeholder = "find color code in HEX"  />
<input id = "color-picker2" type = "text" placeholder = "find color code in RGB"  />
<script>
$(function () {
$('#color-picker1').colorpicker();
});
$(function () {
$('#color-picker2').colorpicker({
format: 'rgba'
});
});
</script>
</div>
</body>
</html>

Output:

Bootstrap color picker output 1

Output:

Bootstrap color picker output 2

Description:

Example #2

The color picker with design color picker example and output.

Code:

<!DOCTYPE html>
<html>
<head>
<title> Bootstrap color picker Example </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.js" > </script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.min.js" > </script>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.min.css"/>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.css"/>
<style>
.custom .colorpicker-saturation {
width: 110px;
height: 200px;
}
.custom .colorpicker-hue,
.custom .colorpicker-alpha {
width: 20px;
height: 200px;
}
</style>
</head>
<body>
<h2> Bootstrap Color Picker </h2>
<div class = "container">
<input id = "color-picker1" type = "text" placeholder = "larg size color picker"  />
<input id = "color-picker2" type = "text" placeholder = "horizontal color picker"  />
<script>
$(function () {
$('#color-picker1').colorpicker({
customClass: 'custom',
sliders: {
saturation: {
maxLeft: 190,
maxTop: 150
},
hue: {
maxTop: 150
},
alpha: {
maxTop: 150
}
}
});
});
$(function () {
$('#color-picker2').colorpicker({
format: 'rgba',
horizontal: true
});
});
</script>
</div>
</body>
</html>

Output:

Bootstrap color picker output 3

Output:

output 4

Description:

Example #3

The color picker with background chathe nge example and output.

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<title> Bootstrap Color picker Example </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.js" > </script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/js/bootstrap-colorpicker.min.js" > </script>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.min.css"/>
<link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/3.2.0/css/bootstrap-colorpicker.css"/>
</head>
<body>
<div class = "container">
<div id = "color-picker">
<h1> Bootstrap Color picker </h1>
<input id = "background-change" type="text" placeholder="change bg color" />
</div>
<script>
$(function () {
$('#background-change').colorpicker({
format: 'rgba'
});
$('#background-change').on('colorpickerChange', function(event) {
$('#color-picker').css('background-color', event.color.toString());
});
});
</script>
</div>
</body>
</html>
</body>
</html>

Output:

output 5

Output:

output 6

Conclusion

The color picker makes web applications colorful as per the user’s requirements. The color picker makes websites themes and background color as per color shades to look attractive and user friendly. The website and web application users have the choice to make magnificent and engaging applications.