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>
<html>
<head>
<style>
a:after {content: " (" attr(href) ")";}
</style><!--from  w  w  w  .jav a 2 s.  c o m-->
</head>

<body>
<p><a href="http://java2s.com">Visit http://java2s.com</a></p>
<p><a href="http://java2s.com"> HTML tutorial</a></p>

</body>
</html>

Related Tutorials