How do I create an interactive button on Tilda that shows a description when clicked? For example, when clicking the ‘Production’ button, a description should appear with photos, information about employees for that industry, and prices.
Creating an Interactive Button on Tilda That Shows Description on Click
To create an interactive button on Tilda that shows a description when clicked, you need to use a combination of HTML, CSS, and JavaScript. There are several ways to implement this functionality: using standard Tilda blocks, Zero Block, or with ready-made modifications.
Table of Contents
- Main Implementation Methods
- Creating Through Standard Tilda Blocks
- Using Zero Block for Customization
- Ready-made Solutions and Modifications
- Example Code for “Production” Button
- Setting Up the Appearance
- Optimization Recommendations
Main Implementation Methods
There are three main ways to create interactive buttons in Tilda:
- Standard Tilda Blocks - using ready-made blocks with additional settings
- Zero Block - creating completely custom blocks from scratch
- Modifications and Libraries - using ready-made solutions from developers
Each method has its advantages and features, which we will examine in more detail below.
Creating Through Standard Tilda Blocks
Step 1: Adding a Button
- Go to the “Blocks” section and select the “Button” category
- Add a BF703 button block or similar
- Set the button text to “Production”
Step 2: Creating Content to Display
- Add blocks with the information you want to show:
- A block with photos
- A block with staff descriptions
- A block with prices
- Group these blocks into one common container
Step 3: Setting Up CSS to Hide Content
/* Style for hiding content by default */
.production-content {
display: none;
transition: all 0.3s ease;
}
.production-content.show {
display: block;
}
Step 4: Adding JavaScript
// Script for toggling content visibility
document.addEventListener("DOMContentLoaded", function() {
const button = document.querySelector('.t-btn[data-field="button"]');
const content = document.querySelector('.production-content');
if (button && content) {
button.addEventListener('click', function(e) {
e.preventDefault();
content.classList.toggle('show');
});
}
});
Using Zero Block for Customization
Zero Block provides more opportunities for creating interactive elements:
Step 1: Creating a Zero Block
- Create a new Zero Block or open an existing one
- Add a button with the text “Production”
- Customize its appearance
Step 2: Adding Content
- Place all necessary elements in the Zero Block:
- Images
- Staff description text
- Price table
- Set the initial state of the content to “Hidden”
Step 3: Setting Up Animations
- Select the content block
- In the animation settings, choose the “Appearance” type
- Configure animation parameters (speed, effect)
Step 4: Connecting Button and Content
// Code for Zero Block
$(document).ready(function() {
// ID of button and content block
const buttonId = '#rec123456789';
const contentId = '#rec987654321';
// Click handler for button
$(buttonId).on('click', function(e) {
e.preventDefault();
$(contentId).slideToggle(500);
t_lazyload_update();
});
});
Important: When working with Zero Block, use the T1093 modifier from the “Other” category to create popup elements.
Ready-made Solutions and Modifications
There are ready-made libraries of modifications that simplify the creation of interactive buttons:
Nolim Library
Provides ready-made modifications for showing hidden blocks:
<!-- Nolim library code -->
<script>
document.addEventListener("DOMContentLoaded", function(){
let shmoreArr = ['#showmore', 'uc-showmore'];
let anchor = true; // scroll to anchor
let hideBtn = false; // hide button on click
let hideBlk = false; // hide block with button
let shmoreBtn = document.querySelectorAll('[href="'+shmoreArr[0]+'"]');
let shmoreBlock = document.querySelectorAll('.'+shmoreArr[1]);
shmoreBlock.forEach(i => i.classList.add("tabshi"));
shmoreBtn.forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
shmoreBlock.forEach(block => {
block.classList.toggle("show");
if (anchor) {
block.scrollIntoView({behavior: "smooth"});
}
});
});
});
});
</script>
TiCode Library
Specially adapted for Tilda:
<!-- TiCode library code -->
<script>
document.addEventListener("DOMContentLoaded", function () {
const TiCodeButtonShow = ['#ti-show', '#rec584999865'];
const TiCodeBlockVisible = false;
const TiCodeHideButton = false;
const TCshowButtons = document.querySelectorAll(`[href="${TiCodeButtonShow[0]}"]`);
const TCshowBlocks = TiCodeButtonShow[1].replace(/#/g, '').split(',').map(id => document.getElementById(id));
TCshowBlocks.forEach(block => {
block.style.transition = "max-height 0.5s ease-in-out, opacity 0.3s ease-in-out";
if (!TiCodeBlockVisible) {
block.style.maxHeight = '0px';
block.style.opacity = '0';
block.style.overflow = 'hidden';
}
});
TCshowButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
TCshowBlocks.forEach(block => {
if (block.style.maxHeight === '0px' || block.style.maxHeight === '') {
block.style.maxHeight = block.scrollHeight + 'px';
block.style.opacity = '1';
} else {
block.style.maxHeight = '0px';
block.style.opacity = '0';
}
});
});
});
});
</script>
Example Code for “Production” Button
Here is a complete example of implementing a “Production” button with content display:
HTML Structure:
<!-- Button -->
<a href="#production-content" class="production-btn">Production</a>
<!-- Content to display -->
<div id="production-content" class="production-content">
<div class="production-grid">
<!-- Photos -->
<div class="production-images">
<img src="photo1.jpg" alt="Production process">
<img src="photo2.jpg" alt="Equipment">
</div>
<!-- Staff description -->
<div class="production-staff">
<h3>Our Specialists</h3>
<p>Experienced engineers and technologists with over 10 years of experience in the industry.</p>
<ul>
<li>25 qualified specialists</li>
<li>5 process engineers</li>
<li>10 machine operators</li>
</ul>
</div>
<!-- Prices -->
<div class="production-prices">
<h3>Services and Prices</h3>
<table>
<tr>
<th>Service</th>
<th>Cost</th>
<th>Timeline</th>
</tr>
<tr>
<td>Machining</td>
<td>from 1500 ₽/hour</td>
<td>from 3 days</td>
</tr>
<tr>
<td>Welding works</td>
<td>from 1200 ₽/hour</td>
<td>from 1 day</td>
</tr>
</table>
</div>
</div>
</div>
CSS Styles:
.production-btn {
display: inline-block;
padding: 12px 24px;
background-color: #007bff;
color: white;
text-decoration: none;
border-radius: 5px;
font-weight: 500;
transition: background-color 0.3s ease;
}
.production-btn:hover {
background-color: #0056b3;
}
.production-content {
display: none;
margin-top: 20px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
}
.production-content.show {
display: block;
animation: fadeIn 0.5s ease-in-out;
}
.production-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.production-images {
grid-column: 1 / -1;
}
.production-images img {
width: 100%;
height: 200px;
object-fit: cover;
margin-bottom: 10px;
}
.production-staff, .production-prices {
background: white;
padding: 15px;
border-radius: 5px;
}
.production-prices table {
width: 100%;
border-collapse: collapse;
}
.production-prices th, .production-prices td {
padding: 8px;
border-bottom: 1px solid #ddd;
text-align: left;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
JavaScript:
document.addEventListener("DOMContentLoaded", function() {
const button = document.querySelector('.production-btn');
const content = document.querySelector('#production-content');
if (button && content) {
button.addEventListener('click', function(e) {
e.preventDefault();
// Toggle content visibility
content.classList.toggle('show');
// Change button text
if (content.classList.contains('show')) {
button.textContent = 'Hide Description';
} else {
button.textContent = 'Production';
}
// Update lazy loading of images
if (typeof t_lazyload_update === 'function') {
t_lazyload_update();
}
});
}
});
Setting Up the Appearance
Responsive Design
/* Responsive grid for mobile devices */
@media (max-width: 768px) {
.production-grid {
grid-template-columns: 1fr;
}
.production-images img {
height: 150px;
}
}
Appearance Animations
/* Various animation effects */
.slide-down {
animation: slideDown 0.5s ease-out;
}
.fade-in {
animation: fadeIn 0.3s ease-in;
}
.zoom-in {
animation: zoomIn 0.4s ease-out;
}
@keyframes slideDown {
from { transform: translateY(-20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
@keyframes zoomIn {
from { transform: scale(0.9); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}
Optimization Recommendations
- Performance: Use
t_lazyload_update()for correct image loading - Accessibility: Add ARIA attributes to improve accessibility
- SEO: Optimize content for search engines
- Testing: Test functionality on different devices and browsers
Optimized JavaScript with Accessibility in Mind:
document.addEventListener("DOMContentLoaded", function() {
const button = document.querySelector('.production-btn');
const content = document.querySelector('#production-content');
if (button && content) {
// Set initial state for screen readers
content.setAttribute('aria-hidden', 'true');
button.setAttribute('aria-expanded', 'false');
button.addEventListener('click', function(e) {
e.preventDefault();
const isExpanded = button.getAttribute('aria-expanded') === 'true';
// Toggle visibility
content.classList.toggle('show');
content.setAttribute('aria-hidden', isExpanded ? 'true' : 'false');
button.setAttribute('aria-expanded', isExpanded ? 'false' : 'true');
// Change button text
button.textContent = isExpanded ? 'Production' : 'Hide Description';
// Update lazy loading
if (typeof t_lazyload_update === 'function') {
t_lazyload_update();
}
});
}
});
Sources
- How to add a button? - Tilda Questions and Answers
- How to add and customize a button in Tilda | NAJES
- How to make hidden blocks show on click on any Tilda button: Tilda modification by Nolim
- Showing and hiding blocks on button click in Tilda| TiCode
- Zero Block: creating custom blocks
- How to create a “Show More” button in Tilda Zero Block
- Showing hidden block on Tilda. Hiding and showing block on Tilda
- Tilda modifications. Showing hidden block on button click in Tilda
Conclusion
Creating an interactive button on Tilda that shows a description when clicked is quite achievable through several methods:
- For beginners - use standard Tilda blocks with basic JavaScript
- For advanced users - apply Zero Block for full customization
- For quick results - use ready-made modification libraries
Key points for successful implementation:
- Properly organize your HTML structure
- Set up CSS for animations and responsiveness
- Use modern JavaScript with accessibility in mind
- Test the result on different devices
Choose the method that best matches your skills and project requirements. All the proposed solutions work stably and can be adapted to your needs.