// Create the button element const button = document.createElement('button'); // Set button properties (optional) button.textContent = 'Click Me'; button.id = 'myButton'; button.style.backgroundColor = 'lightblue'; button.style.padding = '10px 20px'; button.style.border = 'none'; button.style.borderRadius = '5px'; button.style.cursor = 'pointer'; // Add an event listener (optional) button.addEventListener('click', function() { alert('Button clicked!'); }); // Append the button to the body or any other element document.body.appendChild(button);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter