Cool HTML Codes to Copy and Paste – Ready-to-Use Snippets for Your Website
Enhance your web projects instantly with these cool HTML codes to copy and paste. This collection provides ready-to-use snippets for everything from vibrant text effects to responsive layout structures, saving you hours of manual coding.
Essential Text Formatting Snippets
Mastering typographic details is crucial for readability and aesthetics. The following snippets solve common formatting challenges with elegant solutions you can implement immediately.
Gradient Text Effect
Add a stunning gradient to your headings without relying on images. This effect uses pure CSS and is highly customizable.
<h1 class="gradient-text">Shimmering Title</h1>
<style>
.gradient-text {
font-size: 3em;
font-weight: bold;
background: linear-gradient(90deg, #ff7e5f, #feb47b);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>
Animated Underline
Bring links and headers to life with a smooth animated underline. Perfect for drawing attention to interactive elements.
<a href="#" class="animated-underline">Hover over me</a>
<style>
.animated-underline {
position: relative;
color: #007BFF;
text-decoration: none;
}
.animated-underline::after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: #007BFF;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.animated-underline:hover::after {
transform: scaleX(1);
transform-origin: bottom left;
}
</style>
Interactive UI Components
Building user interfaces is faster when you leverage pre-built logic. These components handle interactivity seamlessly.
Collapsible Content Box
Save screen space with this expandable section. Ideal for FAQs or hiding detailed information until requested.
<button onclick="toggleCollapsible()">Toggle Content</button>
<div id="collapsibleContent" class="collapsible">
<p>This content slides in and out smoothly!</p>
</div>
<script>
function toggleCollapsible() {
const content = document.getElementById("collapsibleContent");
content.classList.toggle("active");
}
</script>
<style>
.collapsible {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out;
background-color: #f9f9f9;
padding: 0 15px;
}
.collapsible.active {
max-height: 500px;
padding: 15px;
transition: max-height 0.5s ease-in;
}
</style>
Hover Card
Display additional information on hover without navigating away from the current page. Great for profile previews or product showcases.
<div class="card-container">
<div class="hover-card">
<img src="image.jpg" alt="Card Image">
<div class="card-content">
<h3>Profile Name</h3>
<p>Short bio or description appears here.</p>
</div>
</div>
</div>
<style>
.card-container {
width: 300px;
perspective: 1000px;
}
.hover-card {
position: relative;
width: 100%;
height: 200px;
text-align: center;
transition: transform 0.6s;
transform-style: preserve-3d;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.card-content {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
padding: 20px;
background: rgba(255, 255, 255, 0.95);
backface-visibility: hidden;
display: flex;
flex-direction: column;
justify-content: center;
border-radius: 8px;
}
.card-container:hover .hover-card {
transform: rotateY(180deg);
}
img {
width: 100%;
height: 100%;
object-fit: cover;
backface-visibility: hidden;
}
</style>
Responsive Design Utilities
Ensure your site looks perfect on any device. These media query snippets provide a solid foundation for mobile-first development.
Mobile-First Flexbox Grid
Create a flexible grid system that stacks vertically on small screens and aligns horizontally on larger ones.
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
</div>
<style>
.grid-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.grid-item {
flex: 1 1 100%;
background: #eee;
padding: 20px;
text-align: center;
}
@media (min-width: 600px) {
.grid-item {
flex: 1 1 45%;
}
}
@media (min-width: 900px) {
.grid-item {
flex: 1 1 30%;
}
}
</style>
Hidden Mobile Navigation
Implement a hamburger menu that appears only on smaller screens, keeping the desktop experience clean.
<div class="menu-toggle">☰</div>
<nav class="mobile-nav">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</nav>
<style>
.menu-toggle {
display: none;
cursor: pointer;
}
.mobile-nav {
display: flex;
gap: 15px;
}
@media (max-width: 768px) {
.menu-toggle {
display: block;
}
.mobile-nav {
display: none; /* Typically toggled via JS */
flex-direction: column;
position: absolute;
background: white;
padding: 10px;
border: 1px solid #ddd;
}
}
</style>
Visual Effects and Animations
Add personality to your website with subtle animations and eye-catching visual effects that guide the user's attention.
Shimmer Loading Bar
Indicate progress during page loads with this modern shimmer effect, commonly seen in social media apps.
<div class="loader"></div>
<style>
.loader {
width: 100%;
height: 4px;
background: #f3f3f3;
overflow: hidden;
position: relative;
}
.loader::after {
content: "";
animation: sh 1.5s infinite ease-in-out;
background: linear-gradient(
to right,
#ff7e5f,
#feb47b,
#ff7e5f
);
position: absolute;
top: 0;
left: -100%;
height: 100%;
width: 100%;
}
@keyframes sh {
0% { left: -100%; }
100% { left: 100%; }
}
</style>
3D Flip Card
Create interactive cards that flip to reveal more information on hover. A classic effect for portfolios or product listings.
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<h2>Front</h2>
</div>
<div class="flip-card-back">
<h2>Back</h2>
</div>
</div>
</div>
<style>
.flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #ddd;
perspective: 1000px;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-card-back {
transform: rotateY(180deg);
background-color: #f2f2f2;
}
</style>