id - HTML CSS HTML Global Attribute

HTML CSS examples for HTML Global Attribute:id

Introduction

The id attribute sets a unique identifier to an element.

These identifiers are commonly used with CSS and JavaScript.

The following code demonstrates how to apply a style based on the value of the id attribute.

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>  
<html>  
    <head>      
        <title>Example</title>  
    </head>  
    <style>  
        #w3clink {  <!-- w ww  . j  a va  2 s. c om-->
            background:red;  
            color:white;  
            padding:5px;  
            border: thin solid  black;  
        }  
    </style>  
    <body>  
        <a href="http://java2s.com">web site</a>  
        <p/>  
        <a id="w3clink" href="http://w3c.org">W3C web site</a>  
    </body>  
</html>  

To apply a style based on an id attribute value, you prefix id with the # character when defining the style.


Related Tutorials