1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
| +++
title = "CSS tricks"
description = "CSS-only interactivity — toggles, anchor navigation, hover effects, animations, and responsive images — no JavaScript required."
date = 2026-03-12
[taxonomies]
tags = ["howto"]
+++
Since this theme ships zero JavaScript, CSS is the tool for interactivity. Everything below works in any modern browser with no scripts.
## CSS-only toggle (checkbox hack)
A hidden checkbox, a `<label>`, and the `:checked` selector:
<style>
.toggle-content { display: none; }
#toggle:checked ~ .toggle-content { display: block; }
</style>
<input type="checkbox" id="toggle" hidden>
<label for="toggle" style="cursor:pointer; text-decoration:underline;">Show / hide content</label>
<div class="toggle-content">
This paragraph appears when the label is clicked.
No JavaScript — just CSS `:checked`.
</div>
---
## Anchor navigation (:target)
The `:target` pseudo-class styles the element whose `id` matches the current URL fragment. Click the links below to switch panels.
<style>
.panel { display: none; padding: 1em; margin-top: 0.5em; }
.panel:target { display: block; }
</style>
<a href="#tab1">Tab 1</a> | <a href="#tab2">Tab 2</a> | <a href="#tab3">Tab 3</a>
<div id="tab1" class="panel">
**First panel** — this is the content for Tab 1.
</div>
<div id="tab2" class="panel">
**Second panel** — content for Tab 2 goes here.
</div>
<div id="tab3" class="panel">
**Third panel** — and this is Tab 3.
</div>
---
## Hover effect with CSS transition
<style>
.card {
padding: 1em;
border: 1px solid currentColor;
transition: transform 0.2s ease;
display: inline-block;
}
.card:hover {
transform: scale(1.05);
}
</style>
<div class="card">
Hover over this card to see it scale up slightly.
</div>
---
## CSS animation (@keyframes)
<style>
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.blink {
animation: pulse 2s infinite;
font-weight: bold;
}
</style>
Status: <span class="blink">LIVE</span>
---
## Responsive images with `<picture>`
The `<picture>` element lets the browser choose a source based on media queries:
<picture>
<source srcset="/images/placeholder.svg" media="(max-width: 600px)">
<source srcset="/images/placeholder-wide.svg">
<img src="/images/placeholder-wide.svg" alt="Responsive placeholder image">
</picture>
Resize the browser window to see the image switch between the narrow and wide variants.
|