attr() function - HTML CSS CSS

HTML CSS examples for CSS:Function

Definition and Usage

The attr() function returns the value of an attribute of the selected elements.

CSS Syntax

Value RequireDescription
attribute-name Required. The name of the attribute of the HTML element(s)

The following example inserts the value of the href attribute in parenthesis after each link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
a:after {content: " (" attr(href) ")";}
</style><!--  ww w . ja  v a  2 s .c o m-->

<p><a href="">Visit</a></p>
<p><a href=""> HTML tutorial</a></p>


Related Tutorials