How to Give an ID to a Link in CSS

The CSS ID selector is how you specify a style for a single, unique HTML element, such as a link. You can define the color of the link, the font style and weight or what happens when a visitor hovers over or clicks on the link. The style is defined in a separate section of the HTML file or in completely separate file. Apply it to the "anchor" (link) element using the HTML "id" tag.

Instructions

    • 1

      Open a blank file in a text editor such as Windows Notepad.

    • 2

      Type the line

      <html>

      to begin the HTML document.

    • 3

      Type the line

      <head>

      to start the head portion of the Web page

    • 4

      Type the lines

      <style type="text/css">

      #test {color:orange;}

      </style>

      to create the ID for the link. In this example, the ID is named "test" and it makes the link text orange.

    • 5

      Type the line

      </head>

      to close the head portion of the Web page.

    • 6

      Type the line

      <body>

      to begin the body portion of the Web page.

    • 7

      Type the line

      This is a <a href="http://example.com"> normal link. </a><br/>

      to create a link that does not include the "test" ID.

    • 8

      Type the line

      This is a <a id="test" href="http://www.w3schools.com"> link with an id. </a><br/>

      to create a link that includes the "test" ID.

    • 9

      Type the lines

      </body>

      </html>

      to close the HTML document.

    • 10

      Save the file with the ".html" file extension.

    • 11

      Open the file in any Web browser to view the differences between the two links.

Related Searches:

References

Comments

Related Ads

Featured