You are currently viewing How to Create a Dynamic Card using HTML,CSS and JavaScript?

How to Create a Dynamic Card using HTML,CSS and JavaScript?

Telegram Group Join Now

How to Create a Dynamic Card using HTML, CSS, and JavaScript?

Hello everyone. Welcome to today’s tutorial on Codewithrandom. We’ll learn how to make Dynamic Card Using JavaScript. We Create Color Changing Dynamic Card Where We can Select a Color and That Color is Applied On Our Dynamic Card. We Use Html, Css, And JavaScript.

Dynamic Card using HTML,CSS and JavaScript

In Today’s session, We will use HTML, CSS, and JavaScript to complete this Project.


The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements.

50+ HTML, CSS & JavaScript Projects With Source Code

Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment.

At last we will use JS (JavaScript) which will add logic to make the project responsive from the user end.

I hope you have got an idea about the project.

HTML Code for Dynamic Card

<html lang="en">
    <title>Card With Dynamic Themes</title>
    <!--Google Font-->
    <link rel="preconnect" href="">
    <link href=";600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
    <div class="container">
        <div class="card">
            <img src="">
            <h5>Senior Web Developer</h5>
            <div class="details">
                <div class="column">
                <div class="column">
            <div class="buttons">
        <div class="themes">
            <button class="btn btn1"></button>
            <button class="btn btn2"></button>
            <button class="btn btn3"></button>
            <button class="btn btn4"></button>
            <button class="btn btn5"></button>

    <script src="script.js"></script>

First we’ll start with creating the structure of the project for that as you can see the above code we have used all the necessary elements & attributes. Let us know code the CSS part to add styling and aligned the tags.

5+ HTML CSS Projects With Source Code

CSS Code for Dynamic Card

    padding: 0;
    margin: 0;
    box-sizing: border-box;
    --theme-color: #ff1756;
    background-color: #fafafa;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    height: 420px;
    width: 320px;
    background: linear-gradient(
        to bottom,
        var(--theme-color) 110px,
        #ffffff 110px
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(50,50,50,0.1);
    padding: 50px 0;
.card *{
    font-family: 'Poppins',sans-serif;
    text-align: center;
    letter-spacing: 0.5px;
    font-weight: 600;
    display: block;
    width: 100px;
    height: 100px;
    position: relative;
    border-radius: 50%;
    margin: 0 auto;
    box-shadow: 0 0 0 8px #ffffff;
.card h4{
    color: var(--theme-color);
    font-size: 16px;
    margin: 15px 0 5px 0;
.card h5{
    color: #454545;
    font-weight: 400;
    font-size: 14px;
    width: 100%;
    margin-top: 30px;
    display: flex;
    justify-content: space-around;
.details h2{
    font-weight: 400;
.details span{
    color: var(--theme-color);
    width: 100%;
    display: flex;
    justify-content: space-around;
    margin-top: 30px;
.buttons button{
    width: 130px;
    padding: 8px 0;
    border-radius: 25px;
    border: 3px solid var(--theme-color);
.buttons button:first-child{
    background-color: var(--theme-color);
    color: #ffffff;
.buttons button:last-child{
    background-color: transparent;
    color: var(--theme-color);
    background-color: #ffffff;
    box-shadow: 0 5px 15px rgba(50,50,50,0.1);
    padding: 20px;
    margin-top: 40px;
    display: flex;
    justify-content: space-around;
.themes button{
    height: 25px;
    width: 25px;
    border: 3px solid #dddddd;
    outline: none;
    border-radius: 50%;
    cursor: pointer;
    background-color: #3498db;
    background-color: #ff1756;
    background-color: #1cb65d;
    background-color: #8e44ad;
    background-color: #f4b932;

Second comes the CSS code in which we have styled for the structure we have padded as well as aligned the project so that it is properly situated and doesn’t get messy with suitable CSS elements. Now lets code the JavaScript part to make responsive.

Portfolio Website using HTML and CSS (Source Code)

JavaScript Code for Dynamic Card

const theme = document.querySelector(':root');
const btns = document.querySelectorAll('.btn');


    btn.addEventListener("click", function(e){

        const color = e.currentTarget.classList;

  "--theme-color", "#3498db");
        else if(color.contains("btn2")){
  "--theme-color", "#ff1756");
        else if(color.contains("btn3")){
  "--theme-color", "#1cb65d");
        else if(color.contains("btn4")){
  "--theme-color", "#8e44ad");
  "--theme-color", "#f4b932");

Last stage of the project the JavaScript in which we have added the logical and coded as per the requirement with some conditions. Also we have defined function make the colors responsive to the change the color when the user will click on it. Let us see the Final Output of the project Creating a Dynamic Card using HTML, CSS & JavaScript (Source Code) | Profile Card UI With Dynamic Theme Colors.

100+ JavaScript Projects With Source Code ( Beginners to Advanced)

Final Output Of Dynamic Card Using HTML,CSS and JavaScript

We have Successfully created our Creating a Dynamic Card using HTML, CSS & JavaScript (Source Code). You can use this project for your personal needs and the respective lines of code are given with the code pen link mentioned above.

Restaurant Website Using HTML and CSS

If you find out this Blog helpful, then make sure to search codewithrandom on google for Front End Projects with Source codes and make sure to Follow the Code with Random Instagram page.

Code Idea – codingartist

Written By – Harsh Sawant

Code By – @harshh9

Telegram Group Join Now

Leave a Reply