CSS Portal
Run
Search
« Back to
HTML id Global Attribute
<!DOCTYPE html> <html> <head> <title>Global Attribute id</title> <style> #main { text-align:center; color:red; } #index { color:blue; } </style> </head> <body> <h1 id="main">First level heading.</h1> <p id="index">Paragraph with assigned id as a style identifier.</p> <a href="#main">Using id as an anchor</a> (throws to the specified id). <p>Using JavaScript scripts (changing elements with a specific id):</p> <script> function chg() { var x = document.getElementById("main"); x.style.color = "white"; x.style.backgroundColor = "orange"; } </script> <button onclick="chg()">Click!</button> </body> </html>
If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!
☕ Buy a Coffee