Selecting attribute targets – href

The Class (.) selector and identity (#) selector both target elements to be styled by matching a value assigned to the HTML attribute, class and id respectively.

Additionally CCS can target elements by matchding an attribute which the HTML tag contains.

For example, a CCS selector *[src][alt] would target all elements that contain both src and alt attributes.

Each technique is illustrated in the following example that features an HTML document containing four differant a anchor elements:

/* target all elements with an href attribut */
a[href] {color:red}
/* target all elements with an href and title attributs */
a[href][title] {color:yellow}
/* target all elements with a specific attrib value */
a[href = #top] {color:lime}
<p><a id = "top"> I am an anchor :<BR>You cannot click on me _ I have no href attribute.</a>,</p>

I am an anchor :
You cannot click on me – I have no href attribute.

<p>
<a href="https://java.qbytesworld.com">I am a hyperlink to an internal location: Click on me to visit the destination assigned to the href attribute </a>
</p>

I am a hyperlink to an external location: Click on me to visit the destination assigned to the href attribute

<p>
<a href="http://www.google.com" title="Click here for Google search…">I am a hyperlink to Google search: Click on me to visit the assigned to the href attribute</a>
</p>

I am a hyperlink to Google search: Click on me to visit the assigned to the href attribute

</p>
<p><a href = "#top"> I am a hyperlink to an internal location:<br>
Click on me to go to the anchor at the top of this page.</a></p>

I am a hyperlink to an internal location:
Click on me to go to the anchor at the top of this page.