Creating an NFT Website using HTML, CSS, and JavaScript
Non-fungible tokens (NFTs) are digital assets that are unique and cannot be exchanged for other assets on a one-to-one basis. They are often used to represent digital art, collectibles, and other kinds of virtual property. In this tutorial, we will learn how to create an NFT website using HTML, CSS, and JavaScript.
This code creates an NFT website that displays a list of NFT cards, each with an image, a name, a price, and a “Buy” button. The HTML structure consists of a heading, a container for the NFT cards, and the NFT cards themselves, which are composed of an image, a name, a price, and a button. The CSS styles are used to style the layout and appearance of the NFT cards. The JavaScript code is used to attach an event listener to each “Buy” button, which displays an alert message when clicked.
You can customize the website by modifying the HTML structure, the CSS styles, and the JavaScript code to suit your needs. For example, you can use real NFT images and data, you can add more NFT

Step 1: Set up the HTML structure
The first step is to set up the basic HTML structure of the website. We will create a heading, a container for the NFT cards, and the NFT cards themselves. Each NFT card will consist of an image, a name, a price, and a “Buy” button. Here is the HTML co
<h1>My NFT Collection</h1>
<div class="nft-cards">
<div class="nft-card">
<img src="https://picsum.photos/id/1/300/300" alt="NFT 1" />
<div class="name">NFT 1</div>
<div class="price">$100</div>
<button>Buy</button>
</div>
<div class="nft-card">
<img src="https://picsum.photos/id/2/300/300" alt="NFT 2" />
<div class="name">NFT 2</div>
<div class="price">$200</div>
<button>Buy</button>
</div>
<!-- Add more NFT cards here -->
</div>
Step 2: Add the CSS styles
Next, we will add some CSS styles to style the layout and appearance of the NFT cards. We will use flexbox to align the elements within each NFT card, and we will add some border, padding, and margin to give the cards some visual separation. Here is the CSS code:
.nft-card {
display: flex;
flex-direction: column;
align-items: center;
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
margin: 20px;
width: 250px;
}
.nft-card img {
width: 100%;
}
.nft-card .name {
font-size: 18px;
font-weight: bold;
margin: 10px 0;
}
.nft-card .price {
font-size: 14px;
color: #888;
}
.nft-card button {
border: none;
background-color: #00bcd4;
color: white;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
Step 3: Add the JavaScript code
Finally, we will add some JavaScript code to attach an event listener to each “Buy” button. When a button is clicked, we will display an alert message. Here is the JavaScript code:
const buttons = document.querySelectorAll('button');
buttons.forEach((button) => {
button.addEventListener('click', (event) => {
alert('You clicked the button!');
});
});
This code selects all the buttons on the page using querySelectorAll
, and then it iterates over each button using forEach
. For each button, it attaches an event listener to the click
event, which displays an alert message when the button is clicked.
You can customize the event listener to perform other actions, such as redirecting the user to a payment page or adding the NFT to a cart. For example:
button.addEventListener('click', (event) => {
window.location.href = '/payment';
});
Conclusion
In this tutorial, we learned how to create an NFT website using HTML, CSS, and JavaScript. We set up the HTML structure, added some CSS styles to style the layout and appearance of the NFT cards, and added some JavaScript code to attach an event listener to the “Buy” buttons.
You can customize the website by modifying the HTML structure, the CSS styles, and the JavaScript code to suit your needs. For example, you can use real NFT images and data, you can add more NFT cards, you can display the NFT cards in a grid or a list, you can add a search bar or filtering options, you can add a cart and checkout process, you can add a login system, and so on.
I hope you found this tutorial helpful! If you have any questions or comments, feel free to leave them below. Happy coding!
Want to become a web developer ?
Get complete web development courses on HTML, CSS , JavaScript, Bootstrap, Visual Studio Code, Responsive design and much more…