Code Snippets

An assortment of HTML, CSS, and JavaScript codes. Click on each tab to view.

[JS] Click button to copy

For those who prefer the simplicity of copy-to-clipboard over textarea. This is my personal edit of electric-tenshi's script, so credit goes to them.

The only change I make is to make a few constants so I don't have to edit anything inside writeText.

Copy multiple buttons

This is done by passing the button's image link from onClick function inside img to JS.

HTML

For multiple buttons, just insert different button URL inside copyButton() for each img.

JavaScript
[CSS] Inline description/definition list

Make dd appear next to dt.

It's full moon again,
crazy how time flies.
One might wonder,
if my path was in a right direction.
[JS] Simple, no-iframe clock

A simple clock script that you can use in your site. Customisable with CSS and no more relying on third-party widgets!

Paste the code below in between <script> at the bottom of your HTML file or in a separate JavaScript file. Make sure to give id="time" to the HTML element of your choice, for example <p id="time"></p>

Parameters
Locale
I use 'en-GB', but you can change it to your country's locale. Find the BCP-47 code of your country here.
Hour and Minute
Choose between '2-digit' or 'numeric'. I don't see any difference so far.
timeZone
Accepts TZ identifier code. Find your timezone here.
timeZoneName
'short' if you want an abbreviated name, like GMT/BST. 'long' if you want the complete localised name, like Western Indonesia Time. Other values can be found here.
Notes
  1. Can only target one element. If you give two elements with both id="time", the clock will appear in neither of them.
  2. If you want to display two clocks in different timezones, duplicate the script and change the variables inside document.getElementById() and the parameters to your liking. Let me know if there's an easier way to do this.
  3. Remove setTimeout(getCurrentTime, 1000); if you experience performance issues. This makes the time only update upon refresh.
Credits

W3Schools, vkash8574 on Geeks4Geeks.

[CSS] Bratify your text

Brat generator begone! Now you can have your own brat text for your site.

brat
blurry brat
mirrored brat

If you plan on making a long text, I suggest the text to be wrapped inside a container since the styling messes up the line height. It might also look messy when using bigger font size.

[HTML] Back to Top + Smooth Scrolling

A link that takes you back to the top, preferably placed at the end of a long blog post, long web page, etc.

Add id="top" to the topmost element of your website, like <div class="header" id="top"> or <header id="top">.

[01/09/2026 Update] 7vtia let me know of a much simpler way to achieve this. Instead of using #top, we can simply use do this:

The only difference is to omit the top, leaving only #. This achieves the same outcome, except leaving it to only # is intended to scroll back to the top by default. Thank you, Saif!

Smooth scrolling

Instead of immediately taking you to the top, scroll-behavior: smooth; will smoothen the animation.